示例#1
0
predicted = model.predict(testData.toarray())
print "Predicted : " + str(predicted)

# summarize the fit of the model
test_preds = [1 if elem > 0.5 else 0 for elem in predicted]
print metrics.confusion_matrix(testModY, test_preds)

recall = metrics.recall_score(testModY, test_preds)
precision = metrics.precision_score(testModY, test_preds)

sbuf = str(recall) + "\n"
sbuf += str(precision) + "\n"

print sbuf

print "=====" + str(model.get_params().keys())
param = {
    'alpha_1': [1e-06],
    'alpha_2': [1e-06],
    'compute_score': [False],
    'copy_X': [True],
    'fit_intercept': [True],
    'lambda_1': [1e-06],
    'lambda_2': [1e-06],
    'n_iter': [300, 400, 500],
    'normalize': [False],
    'tol': [0.001],
    'verbose': [False]
}
grid = GridSearchCV(estimator=model, param_grid=param)
grid.fit(trainData.toarray(), trainModY)
X_test = X_test[features]

print (y_train)
y_train = y_train[['Target']]

print (y_train)
y_test = y_test[['Target']]


# corr = data.corr()

# param_grid = {'C': [4.7, 4.8, 4.9, 5.0], 'gamma': [ 0.000009, 0.000010, 0.000011, 0.000012]}


print(X_train)
print(y_train)

# regressor = LinearRegression()
regressor = BayesianRidge()
#regressor.fit(X_train, y_train.squeeze().tolist())
regressor.fit(X_train, y_train.squeeze().tolist())

print(regressor.score(X_test, y_test.squeeze().tolist()))

print(regressor.get_params())
y_predict = regressor.predict(X_test)
print(y_predict)

plt.plot(y_test.squeeze().tolist(), y_predict, 'o');
plt.show()
示例#3
0
tY = test[:, column_count - 1]

# Setting up algorithm
rf = BayesianRidge()

# Train model
rf.fit(X=x, y=y)

# Get prediction results
result = rf.predict(tX)

print("Result")
print("------")
print(result)

# Analyze performance
print("Performance")
print("-----------")
print(("Mean Absolute Error", mean_absolute_error(tY, np.array(result))))

# Dump pickle files
print((df_mapper.features))
print((rf.get_params()))

joblib.dump(df_mapper, mapper_pkl, compress=3)
joblib.dump(rf, estimator_pkl, compress=3)

# Build pmml
command = "java -jar converter-executable-1.1-SNAPSHOT.jar --pkl-mapper-input mapper.pkl --pkl-estimator-input estimator.pkl --pmml-output mapper-estimator.pmml"
os.system(command)
示例#4
0
    #-----------------------------------------------------------------------------------
    # Posterior Density estimate:

    count, bins, ignored = plt.hist(sigmas, 40, density=True, color='black')
    plt.xlabel(r"$\sigma$")
    plt.ylabel(r"value")
    plt.title(r"Trace plot of $\sigma$ posterior draws")
    plt.show()

# #############################################################################
# Fit the Bayesian Ridge Regression and an OLS for comparison
clf = BayesianRidge(n_iter=500, compute_score=True)

clf.fit(X, y)
beta_hat = clf.coef_

X[:10, :p]

n, k = X.shape
clf.get_params()
pred = clf.predict([[1, 0.56, 0.88]], return_std=True)
pred  # yhat
yhat = pred[0]
se_yhat = pred[1]
R2 = clf.score(X, y)
R2

ols = LinearRegression()
ols.fit(X, y)
示例#5
0
rf = BayesianRidge()

# Train model
rf.fit(X=x, y=y)

# Get prediction results
result = rf.predict(tX)

print "Result"
print "------"
print result

# Analyze performance
print "Performance"
print "-----------"
print "Root Mean Squared Error", mean_squared_error(tY, np.array(result)) ** 0.5
print "Mean Absolute Error", mean_absolute_error(tY, np.array(result))

# Dump pickle files
print df_mapper.features
print rf.get_params()

joblib.dump(df_mapper, mapper_pkl, compress = 3)
joblib.dump(rf, estimator_pkl, compress = 3)

# Build pmml
command = "java -jar converter-executable-1.1-SNAPSHOT.jar --pkl-mapper-input mapper.pkl --pkl-estimator-input estimator.pkl --pmml-output mapper-estimator.pmml"
os.system(command)