0
this example을 SQL 서버 데이터베이스에있는 일부 소셜 미디어 데이터에 적용하려고합니다.SciKit-Learn Text Classification from ODBC
저는 'bunches'라는 단어가 포함 된 소셜 미디어 게시물 만 사용하도록 의도적으로 교육 및 테스트 세트를 강제했습니다. 따라서 모든 알고리즘을 통해이 단어를 실행하면 매우 높은 f- 점수를 기대할 수 있습니다. 대신 나는 약 2-4 %의 f- 점수를 얻고 있습니다. 나는 알고리즘에 데이터를 올바르게 공급하지 않는다고 생각한다. 내가 잘못 뭐하는 거지 그래서
n_samples: 237, n_features: 26
['almonds' 'amp' 'best' 'bowl' 'box' 'bunches' 'cereal' 'cheerios' 'crunch'
'day' 'don' 'eat' 'eating' 'good' 'gt' 'honey' 'http' 'just' 'like' 'lol'
'love' 'miss' 'morning' 'oats' 'rt' 'want']
:
from __future__ import print_function
import numpy as np
from time import time
from sklearn.feature_extraction.text import TfidfVectorizer
import pyodbc
import pprint
#local windows connection
train = []
db = pyodbc.connect('DRIVER={SQL Server Native Client 11.0};SERVER=SERVER_IP;DATABASE=DB_NAME;Trusted_Connection=Yes;')
cursor = db.cursor()
training_query = "SELECT top 2 percent postTitle FROM dbo.All_CH_Posts where monitorID ='1168136050' and postTitle like '%bunches%' ORDER BY NEWID()"
trainquery = cursor.execute(training_query)
traindata = cursor.fetchall()
for row in traindata:
train.extend(row)
test = []
test_query = "SELECT top 1 percent postTitle FROM dbo.All_CH_Posts where monitorID ='1168136050' and postTitle like '%bunches%' ORDER BY NEWID()"
testquery = cursor.execute(test_query)
testdata = cursor.fetchall()
for row in testdata:
test.extend(row)
print('traindata')
pp.pprint(traindata)
print('testdata')
pp.pprint(testdata)
print('data loaded')
# split a training set and a test set
y_train = train
y_test =test
print("Extracting features from the training dataset using a sparse vectorizer")
t0 = time()
vectorizer = TfidfVectorizer(decode_error='ignore',sublinear_tf=True,
stop_words='english', lowercase=True, min_df=20)
X_train = vectorizer.fit_transform(train)
duration = time() - t0
print("Extracting features from the test dataset using the same vectorizer")
t0 = time()
X_test = vectorizer.transform(test)
duration = time() - t0
print("n_samples: %d, n_features: %d" % X_test.shape)
feature_names = np.asarray(vectorizer.get_feature_names())
print(feature_names)
나는 의도적으로 내 희소 행렬에 어떤 단어를 살펴 얻을 높은 min_df을 설정? 아니면이 문제를 잘못된 방식으로 생각하고 있습니까/텍스트 분류에 대한 오해가 있습니까? @AndreasMueller 및 @Guru에
그럼 라벨은 무엇입니까? 이 코드에서는 텍스트를 레이블로 사용하는 것처럼 보이는''y_train = train''을 설정합니다. 이것은 상당히 혼란 스럽습니다. 어떤 f-score를 계산하고 있습니까? 사실, 모든 텍스트가 공통적 인 특징을 가지고 있다면,이 특징은 정보가 아니며 f- 점수가 0이어야합니다 (iirc). –
@AndreasMueller 코멘트에 덧붙여, 예제 코드의 훈련 세트 ** 섹션에서 ** 카테고리를로드하십시오. 이는 분류를 위해 카테고리/라벨을 지정해야한다는 것을 의미합니다. 'data_train.target_names'의 값을 확인할 수 있습니까? 이것은 분류하려고하는 클래스 목록이어야합니다. –
@ 구루 알 겠어. 레이블/범주를 추가하면 모니터 ID가됩니다. 나는 데이터가 "select monitorID, postTitle from Table"이라는 튜플의 목록이 될 것이고 vectorizor를 파손시킬 것이기 때문에 벡터를 통과하는 데이터에 레이블을 어떻게 연결해야하는지 명확하지 않다. – dreyco676