Пример #1
0
class _RidgeClassifierCVImpl:
    def __init__(self, **hyperparams):
        self._hyperparams = hyperparams
        self._wrapped_model = Op(**self._hyperparams)

    def fit(self, X, y=None):
        if y is not None:
            self._wrapped_model.fit(X, y)
        else:
            self._wrapped_model.fit(X)
        return self

    def predict(self, X):
        return self._wrapped_model.predict(X)

    def decision_function(self, X):
        return self._wrapped_model.decision_function(X)
Пример #2
0
def build_matrix_df_old(pickle_filename):
    flickr_results = pickle.load(open(pickle_filename))
    combined_scores, all_reqd_tags = curate_imagescores(flickr_results)
    matrix, outcome, location_dict = build_all_rows(combined_scores,
                                                    all_reqd_tags)
    data = {
        'matrix': matrix,
        'outcome': outcome,
        'rows': all_reqd_tags,
        'location_dict': location_dict
    }
    pickle.dump(data, open(os.path.join('./cache', 'flickr_data.pickle'),
                           'w+'))
    print(matrix.wildlife.tolist())
    dt = DecisionTreeClassifier(random_state=0).fit(matrix, outcome)
    pickle.dump(
        dt,
        open(os.path.join('./cache', 'flickr_model_decisiontree.pickle'),
             'w+'))
    print('Feature Importance', dt.feature_importances_)
    predict = dt.predict_proba(matrix)
    print('Probability', predict)
    act_predict = dt.predict(matrix)
    print(act_predict.tolist())
    score = dt.score(matrix, outcome)
    print('Shape', score)
    rc = RidgeClassifierCV(cv=3, normalize=True).fit(matrix, outcome)
    pickle.dump(
        rc,
        open(os.path.join('./cache', 'flickr_model_ridgeclasscv.pickle'),
             'w+'))
    rc_df = rc.decision_function(matrix)
    for ind_row in rc_df:
        print(list(ind_row))
    #print(rc_df)
    raw_input('Done With Creating Model')
Y_lr = lr.predict(X_test)
print(accuracy_score(Y_test, Y_lr))

# In[14]:

svc = SVC(C=1.0, kernel='rbf')
svc.fit(X_train, Y_train)
Y_SVC = svc.predict(X_test)
accuracy_score(Y_test, Y_SVC)

# In[15]:

rc = RidgeClassifierCV(alphas=(0.1, 1.0, 10.0))
rc.fit(X_train, Y_train)
Y_rc = rc.predict(X_test)
rc.decision_function(X_test)

# In[16]:

tr = DecisionTreeClassifier(criterion='gini')
tr.fit(X_train, Y_train)
Y_tr = tr.predict(X_test)
accuracy_score(Y_test, Y_tr)

# In[17]:

rf = RandomForestClassifier(n_estimators=10, criterion='gini')
rf.fit(X_train, Y_train)
Y_rf = rf.predict(X_test)
accuracy_score(Y_test, Y_rf)