<jupyter_start><jupyter_text>Linear Regression<jupyter_code># y = ax + b

X = np.array([1,2,3,4,5,6,7,8,9,10])
X = X.astype(float)

y = 2*X + 10

X = X[:, np.newaxis]
X = np.hstack([X, np.ones((X.shape[0],1), dtype=X.dtype)])

lm = h2o4gpu.LinearRegression()
lm.fit(X, y)

print('Linear Regression')
print('Predicted:', lm.predict(np.array([[15.0, 1.0], [16.0, 1.0]])))
print('Coefficients:', lm.X)

# sklearn
X = np.array([1,2,3,4,5,6,7,8,9,10])
X = X[:, np.newaxis]
# Values to predict
X_test = np.array([15, 16])
X_test = X_test[:, np.newaxis]

sk_lm = linear_model.LinearRegression()
sk_lm.fit(X, np.transpose(y))

print('------------')
print('scikit-learn')
print('Predicted:', sk_lm.predict(X_test))
print('Coefficients:', sk_lm.coef_)<jupyter_output>Linear Regression
Predicted: [[ 39.93816196  41.93188356]]
Coefficients: [[  1.9937216   10.03233797]]
------------
scikit-learn
Predicted: [ 40.  42.]
Coefficients: [ 2.]<jupyter_text>Logistic Regression  Data Prep<jupyter_code>iris = datasets.load_iris()

X = iris.data
y = iris.target

dfX = pd.DataFrame(X)
dfy = pd.DataFrame(y)

dfy.loc[:,0].value_counts()
# making it a binary problem
# removing third class
X = X[y != 2]
y = y[y != 2]

# subtracting the mean
X -= np.mean(X, 0)
X_test = X[np.r_[40:50,90:100]]
y_test = y[np.r_[40:50,90:100]]
X = X[np.r_[:40,50:90]]
y = y[np.r_[:40,50:90]]<jupyter_output><empty_output><jupyter_text>sklearn logistic regression<jupyter_code>cs = l1_min_c(X, y, loss='log') * np.logspace(0, 3)
start = time.time()
clf = linear_model.LogisticRegression(C = 1.0, penalty = 'l1'
                         #, tol=1e-6
                        )
coefs_ = []
for c in cs:
    clf.set_params(C=c)
    clf.fit(X, y)
    coefs_.append(clf.coef_.ravel().copy())
print(time.time() - start)
coefs_ = np.array(coefs_)
plt.plot(np.log10(cs), coefs_)
ymin, ymax = plt.ylim()
plt.xlabel('log(C)')
plt.ylabel('Coefficients')
plt.title('Logistic Regression Path')
plt.axis('tight')
plt.show()
print(coefs_.shape)
y_pred = clf.predict(X_test)
y_pred
clf.predict_proba(X_test)<jupyter_output><empty_output><jupyter_text>H2O4GPU<jupyter_code>classification = True
logreg = h2o4gpu.LogisticRegression(alpha_max = 1.0
                                    , alpha_min = 1.0
                                   )
start = time.time()
model = logreg.fit(X, y)
print(time.time() - start)
model
y_pred_h2o = model.predict(X_test)
y_pred_h2o
print("Xvsalpha")
print(logreg.x_vs_alphapure)
print(model.x_vs_alphapure)

print("np.shape(Xvsalpha)")
print(np.shape(logreg.x_vs_alphapure))
print(np.shape(model.x_vs_alphapure))

error_train = logreg.error_vs_alpha
if classification:
    print("logloss_train")
else:
    print("rmse_train")
print(error_train)

error_train = model.error_vs_alpha
if classification:
    print("logloss_train")
else:
    print("rmse_train")
print(error_train)

print("Best lambdas")
lambdas = logreg.lambdas_best
print(lambdas)
print(model.lambdas_best)

print("Best alphas")
alphas = logreg.alphas_best
print(alphas)
print(model.alphas_best)

print("Best tols")
tols = logreg.tols_best
print(tols)
print(model.tols_best)
logreg.x_vs_alphapure
model.X_full
model.X_best
logreg = h2o4gpu.LogisticRegression(alpha_max = 1.0, 
                                    alpha_min = 1.0,
                                    give_full_path = 1,
                                    n_lambdas = 50,
                                    glm_stop_early = False
                                   )
start = time.time()
logreg.fit(X, y)
print(time.time() - start)
logreg.lambdas_full<jupyter_output>136.42706084251404<jupyter_text>136 seconds for 80 x 4  training_frame seems excessive<jupyter_code>y_pred_h2o
logreg_path = h2o4gpu.GLM(family='logistic', verbose=100)
logreg_path.fit(X, y)
logreg_path.predict(X_test)<jupyter_output>no data
no data
no data
no data
no data
no data
Correct prediction inputs
Detected np.float64 data
Detected np.float64
double precision fit
thecount=20 count_full_value=0 count_short_value=10 n=4 NUMALLOTHER=6 m_valid=20<jupyter_text>H2O3 Logistic Regression<jupyter_code>import h2o
from h2o.estimators import H2OGeneralizedLinearEstimator 
h2o.init()
hf_X = h2o.H2OFrame(X)
hf_y = h2o.H2OFrame(y)
hf_X_test = h2o.H2OFrame(X_test)
hf_y_test = h2o.H2OFrame(y_test)
hf_y = hf_y.asfactor()
hf_y_test = hf_y_test.asfactor()
hf = hf_X.cbind(hf_y)
h2olr = H2OGeneralizedLinearEstimator(family = 'binomial')
start = time.time()
h2olr.train(x=['C1','C2', 'C3', 'C4'] ,y='C10', training_frame=hf)
print(time.time()- start)
hf_predict = h2olr.predict(hf_X_test)
hf_predict.head(10)
hf_predict.tail(10)
h2o.cluster().shutdown()<jupyter_output>H2O session _sid_b969 closed.
{'fraction_non_alphanumeric': 0.15226249195796698, 'fraction_numerical': 0.04803774394166845, 'mean_word_length': 4.0972677595628415, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '127624', 'license': 'Apache-2.0', 'n_tokens_mistral': 2083, 'n_tokens_neox': 1950, 'n_words': 318, 'path': 'tests/python/small/test-LinearModels.ipynb', 'repo_name': 'LazyBrainAI/h2o4gpu', 'size': '4663'}