Exemple #1
0
class NuSVRImpl():

    def __init__(self, nu=0.5, C=1.0, kernel='rbf', degree=3, gamma='auto_deprecated', coef0=0.0, shrinking=True, tol=0.001, cache_size=200, verbose=False, max_iter=(- 1)):
        self._hyperparams = {
            'nu': nu,
            'C': C,
            'kernel': kernel,
            'degree': degree,
            'gamma': gamma,
            'coef0': coef0,
            'shrinking': shrinking,
            'tol': tol,
            'cache_size': cache_size,
            'verbose': verbose,
            'max_iter': max_iter}
        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)
Exemple #2
0
 def __init__(self,
              nu=0.5,
              C=1.0,
              kernel='rbf',
              degree=3,
              gamma='auto_deprecated',
              coef0=0.0,
              shrinking=True,
              tol=0.001,
              cache_size=200,
              verbose=False,
              max_iter=(-1)):
     self._hyperparams = {
         'nu': nu,
         'C': C,
         'kernel': kernel,
         'degree': degree,
         'gamma': gamma,
         'coef0': coef0,
         'shrinking': shrinking,
         'tol': tol,
         'cache_size': cache_size,
         'verbose': verbose,
         'max_iter': max_iter
     }
     self._wrapped_model = SKLModel(**self._hyperparams)
Exemple #3
0
 def fit(self, X, y=None):
     self._sklearn_model = SKLModel(**self._hyperparams)
     if (y is not None):
         self._sklearn_model.fit(X, y)
     else:
         self._sklearn_model.fit(X)
     return self
Exemple #4
0
			'MinCovDet':MinCovDet(),
			'MinMaxScaler':MinMaxScaler(),
			'MiniBatchDictionaryLearning':MiniBatchDictionaryLearning(),
			'MiniBatchKMeans':MiniBatchKMeans(),
			'MiniBatchSparsePCA':MiniBatchSparsePCA(),
			'MultiTaskElasticNet':MultiTaskElasticNet(),
			'MultiTaskElasticNetCV':MultiTaskElasticNetCV(),
			'MultiTaskLasso':MultiTaskLasso(),
			'MultiTaskLassoCV':MultiTaskLassoCV(),
			'MultinomialNB':MultinomialNB(),
			'NMF':NMF(),
			'NearestCentroid':NearestCentroid(),
			'NearestNeighbors':NearestNeighbors(),
			'Normalizer':Normalizer(),
			'NuSVC':NuSVC(),
			'NuSVR':NuSVR(),
			'Nystroem':Nystroem(),
			'OAS':OAS(),
			'OneClassSVM':OneClassSVM(),
			'OrthogonalMatchingPursuit':OrthogonalMatchingPursuit(),
			'OrthogonalMatchingPursuitCV':OrthogonalMatchingPursuitCV(),
			'PCA':PCA(),
			'PLSCanonical':PLSCanonical(),
			'PLSRegression':PLSRegression(),
			'PLSSVD':PLSSVD(),
			'PassiveAggressiveClassifier':PassiveAggressiveClassifier(),
			'PassiveAggressiveRegressor':PassiveAggressiveRegressor(),
			'Perceptron':Perceptron(),
			'ProjectedGradientNMF':ProjectedGradientNMF(),
			'QuadraticDiscriminantAnalysis':QuadraticDiscriminantAnalysis(),
			'RANSACRegressor':RANSACRegressor(),
Exemple #5
0

dataset = read_csv('air_pollution.csv')
examDf = DataFrame(dataset)
new_examDf = DataFrame(examDf.drop('data',axis=1))


X_train,X_test,y_train,y_test = (new_examDf.iloc[:220,:7],new_examDf.iloc[220:-1,:7],new_examDf.AQI[1:221],new_examDf.AQI[221:])
X_train = np.array(X_train)
X_test = np.array(X_test)
y_test = np.array(y_test)
y_train = np.array(y_train)



clf = NuSVR(nu=0.5, C=1.0, kernel='linear', degree=3, gamma='auto')
clf.fit(X_train,y_train)
y_pred = clf.predict(X_test)


RMSE = sqrt(mean_squared_error(y_test,y_pred))
print ('RMSE: %.3f' % RMSE)
MAE = mean_absolute_error(y_test,y_pred)
print('MAE: %.3f' % MAE)
e = (abs((y_test - y_pred)/y_test))
print('mBA:%.3f' % np.mean(e))
plt.figure()
plt.plot(range(len(y_pred)),y_pred,'b',label="predict")
plt.plot(range(len(y_pred)),y_test,'r',label="test")
plt.legend(loc="upper right")
plt.xlabel("predict——test")
Exemple #6
0
from scipy.stats.stats import pearsonr
import numpy as np
from sklearn.svm.classes import NuSVR
from sklearn.datasets.svmlight_format import load_svmlight_file

if __name__ == '__main__':

    trainfile = './data/svm_train.txt'

    problem = svm_read_problem(trainfile)
    rank_model = svm_train(problem[0][:-100], problem[1][:-100],
                           '-s 4 -h 0 -m 1000')

    predicted_f, _, _ = svm_predict(
        np.ones(100).tolist(), problem[1][-100:], rank_model)

    scores_rank_test = problem[0][-100:]

    print(("Pearson correlation for fold = %f" %
           pearsonr(scores_rank_test, predicted_f)[0]))

    svr = NuSVR()

    lingfeat, y = load_svmlight_file(trainfile)

    svr.fit(lingfeat[:-100], y[:-100])
    y_pred = svr.predict(lingfeat[-100:])

    print(("Pearson correlation for fold = %f" %
           pearsonr(scores_rank_test, y_pred)[0]))