text_plain_output_1.png
from sklearn.calibration import CalibratedClassifierCV

from sklearn.feature_extraction.text import CountVectorizer

from sklearn.linear_model import SGDClassifier

from sklearn.metrics.classification import accuracy_score, log_loss

from sklearn.metrics.classification import accuracy_score, log_loss

import numpy as np

import numpy as np # linear algebra

from sklearn.metrics.classification import accuracy_score, log_loss
cross_validation_size = y_cv.shape[0]
random_cross_validation = np.zeros((cross_validation_size, 9))
for i in range(cross_validation_size):
    random_prob = np.random.rand(1, 9)
    random_cross_validation[i] = (random_prob / sum(sum(random_prob)))[0]

from sklearn.feature_extraction.text import CountVectorizer
gene_vectorizer = CountVectorizer()
train_gene_feature_onehotCoding = gene_vectorizer.fit_transform(x_train['Gene'])
test_gene_feature_onehotCoding = gene_vectorizer.transform(x_test['Gene'])
cv_gene_feature_onehotCoding = gene_vectorizer.transform(x_cv['Gene'])

from sklearn.linear_model import SGDClassifier
from sklearn.calibration import CalibratedClassifierCV
alpha = [10 ** i for i in range(-5, 1)]
cv_log_error_array = []
for i in alpha:
    clf = SGDClassifier(loss='log', alpha=i, random_state=42)
    clf.fit(train_gene_feature_onehotCoding, y_train)
    calibration = CalibratedClassifierCV(clf, method='sigmoid')
    calibration.fit(train_gene_feature_onehotCoding, y_train)
    y_cv_predict = calibration.predict_proba(cv_gene_feature_onehotCoding)
    cv_log_error_array.append(log_loss(y_cv, y_cv_predict))
    print('For values of alpha = ', i, 'The log loss is:', log_loss(y_cv, y_cv_predict))