Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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('
Train Report
')
print(classification_report(y_train, train_y_pred))

print('Test Report
')
print(classification_report(y_test, test_y_pred))
Comment

PREVIOUS NEXT
Code Example
Python :: django login url 
Python :: python to postgresql 
Python :: sort 2 lists together python 
Python :: getting multiple of 5 python 
Python :: django authenticate with email 
Python :: How to take multiple input form python 
Python :: uppercase python 
Python :: flask No application found. Either work inside a view function or push an application context 
Python :: python run bat in new cmd window 
Python :: traversing dictionary in python 
Python :: python -c 
Python :: numpy reshape (n ) to (n 1) 
Python :: python library for downsampling a photo 
Python :: python os.path.join 
Python :: count number of objects django template 
Python :: quantile calcultion using pandas 
Python :: how to sort values by index pandas 
Python :: structure ternaire python 
Python :: inpuit inf terfminal ppython 
Python :: find index of element in array python 
Python :: python module path 
Python :: how to add value in array django 
Python :: twitter api python 
Python :: reshape (n ) to (n 1) 
Python :: python internship 
Python :: python 2 print in same line 
Python :: choose value none in pandas 
Python :: create new dataframe from existing data frame python 
Python :: python bool 
Python :: Python NumPy asarray Function Syntax 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =