Horje
text classification Code Example
text classification
from sklearn.linear_model import SGDClassifier
from sklearn.pipeline import Pipeline
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.calibration import CalibratedClassifierCV

model = Pipeline([('vect', CountVectorizer(ngram_range=(1, 10),min_df=5, max_df = .70)),
                ('tfidf', TfidfTransformer(norm='l1')),
                ('clf', CalibratedClassifierCV(base_estimator= SGDClassifier(penalty='elasticnet',alpha=0.001, max_iter=500,l1_ratio=.1,random_state=45),method = 'isotonic')),
               ])
model.fit(X_train, y_train)


# Predictions
test_y_pred = model.predict(X_test)
train_y_pred = model.predict(X_train)

print('Train accuracy %s' %accuracy_score(train_y_pred, y_train))
print('Test accuracy %s' % accuracy_score(test_y_pred, y_test))

print('\nTrain Report\n')
print(classification_report(y_train, train_y_pred))

print('Test Report\n')
print(classification_report(y_test, test_y_pred))




Python

Related
pytesseract restrict char Code Example pytesseract restrict char Code Example
django changing boolean field from view Code Example django changing boolean field from view Code Example
python-telegram-bot send file Code Example python-telegram-bot send file Code Example
convert numpy array to tfrecord and back Code Example convert numpy array to tfrecord and back Code Example
python count empty lines in text file Code Example python count empty lines in text file Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
10