示例#1
0
    'n_estimators': 500,
    'max_depth': 4,
    'min_samples_split': 2,
    'learning_rate': 0.01,
    'loss': 'ls',
}
clf = ensemble.GradientBoostingRegressor(**params)

clf.fit(X_train, y_train)

y_pred = clf.predict(X_test)
mse = mean_squared_error(y_test, clf.predict(X_test))
print('MSE: %.4f' % mse)


columns = list(boston.feature_names) + ['target']
data = np.c_[boston.data, boston.target]
df = pd.DataFrame(data=data, columns=columns)


model_file = 'boston_gbr.pkl'
print('Writing model')
with open(model_file, 'wb') as f:
    pickle.dump(clf, f)


print('Writing dataset schema')
schema = build_schema(df)
with open('boston_schema.json', 'w') as f:
    json.dump(schema, f, indent=4, sort_keys=True)
示例#2
0
    'has_profile_picture', 'Private.account'
]
target_name = 'rating'

dtypes = {
    'Number.of.posts': 'uint32',
    'Number.of.people.they.follow': 'uint32',
    'Number.of.followers': 'uint32',
    'has_profile_picture': 'bool',
    'Private.account': 'bool',
}

data = pd.read_csv('labelled_1000_inclprivate.csv', dtype=dtypes)

X_train = data[columns]
y_train = data[target_name]
original = pd.concat([X_train, y_train], axis=1)

rfc = RandomForestClassifier(n_estimators=100)
rfc.fit(X_train, y_train)
print(rfc.predict_proba(X_train))

print('Writing model')
with open('instgram_rf.pkl', 'wb') as f:
    cloudpickle.dump(rfc, f)

print('Writing dataset schema')
schema = build_schema(original)
with open('instagram.json', 'w') as f:
    json.dump(schema, f, indent=4, sort_keys=True)
示例#3
0


#model
from statsmodels.tsa.vector_ar.vecm import VECM
vecm = VECM(endog = endog,exog=exog,exog_coint=exog_coint, k_ar_diff = 1, coint_rank = 5, deterministic ='cili')
vecm_fit = vecm.fit()



import pickle
with open('VECM_result.pkl', 'wb') as f:
  pickle.dump(vecm_fit ,f)





pip install git+https://github.com/ml-libs/mlserve.git

import mlserve
import json
from mlserve import build_schema

data_schema = mlserve.build_schema(df1)
with open('ReSAKSS.json', 'w') as f:
    json.dump(data_schema, f)
    

    
示例#4
0
X_train, X_test, y_train, y_test = train_test_split(X,
                                                    y,
                                                    test_size=0.2,
                                                    random_state=123,
                                                    stratify=y)

pipeline = make_pipeline(StandardScaler(),
                         RandomForestRegressor(n_estimators=100))

hyperparameters = {
    'randomforestregressor__max_features': ['auto', 'sqrt', 'log2'],
    'randomforestregressor__max_depth': [None, 5],
}

clf = GridSearchCV(pipeline, hyperparameters, cv=5)
clf.fit(X_train, y_train)

pred = clf.predict(X_test)
print(r2_score(y_test, pred))
print(mean_squared_error(y_test, pred))

model_file = 'wine_quality_rf.pkl'
print('Writing model')
with open(model_file, 'wb') as f:
    pickle.dump(clf, f)

print('Writing dataset schema')
schema = mlserve.build_schema(data)
with open('wine_quality_schema.json', 'w') as f:
    json.dump(schema, f, indent=4, sort_keys=True)