예제 #1
0
from readFile import readDataSet
from sklearn.svm import SVR
from sklearn.externals import joblib
from sklearn.model_selection import GridSearchCV
import numpy as np

data, nrows, ncols = readDataSet("YearPredictionMSD20.txt")
X = data[:, 1:91]
y = data[:, 0]

# clf = SVR(C=1.0, epsilon=0.2,max_iter=100000000,degree = 3, coef0 = 0 ,kernel="poly",verbose=True)
params = {
    'kernel': ['rbf', 'linear', 'poly'],
    'C': [0.0001, 0.001, 0.01, 0.1, 1, 10, 50, 100],
    'epsilon': [0.2, 1, 0.001, 0.01, 10]
}
clf = GridSearchCV(SVR(degree=3, max_iter=1000, verbose=True),
                   params,
                   cv=5,
                   verbose=True)
clf.fit(X, y)
y_pred = clf.predict(X)
print y_pred, y
print(np.sum((y_pred - y)**2) / len(X))
print clf.score(X, y)
print clf.best_estimator_
print clf.best_score_
print clf.best_params_
print clf.cv_results_

# print clf.support_
예제 #2
0
from readFile import readDataSet
from sklearn.linear_model import Ridge
from sklearn.externals import joblib
from sklearn.model_selection import GridSearchCV
import numpy as np
from sklearn.preprocessing import StandardScaler

data, nrows, ncols = readDataSet("YearPredictionMSD100.txt")
X = data[:, 1:91]
y = data[:, 0]

X = StandardScaler().fit_transform(X)
clf = Ridge(alpha=100, max_iter=-1, solver="lsqr")
params = {'alpha': [0.0001, 0.001, 0.01, 0.1, 1, 10, 100, 1000, 10000]}
# clf = GridSearchCV(Ridge(max_iter=-1), params,  cv = 5,verbose=True)
clf.fit(X, y)
# print clf.best_estimator_
# print clf.best_score_
# print clf.best_params_
# print clf.cv_results_
# print clf.cv_results_['mean_test_score']

y_pred = clf.predict(X)
print y_pred, y
print(np.sum((y_pred - y)**2) / len(X))
print clf.score(X, y)

data, nrows, ncols = readDataSet("YearPredictionMSDTest10.txt")
X = data[:, 1:91]
y = data[:, 0]