image_output_11.png image_output_14.png image_output_13.png image_output_5.png image_output_7.png image_output_4.png image_output_8.png image_output_16.png image_output_6.png image_output_12.png image_output_3.png image_output_2.png image_output_1.png image_output_10.png image_output_15.png image_output_9.png
from sklearn.linear_model import LinearRegression

from sklearn.metrics import median_absolute_error

from sklearn.metrics import r2_score

from sklearn.model_selection import train_test_split

from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import make_scorer
from sklearn.metrics import r2_score
from sklearn.metrics import median_absolute_error
X_train, X_test, y_train, y_test = train_test_split(train['acoustic_data'].values[::25].reshape(-1, 1), train['time_to_failure'].values[::25], test_size=0.2)
quake_linear_model = LinearRegression()
quake_linear_model.fit(X_train, y_train)
y_train_pred = quake_linear_model.predict(X_train)
y_test_pred = quake_linear_model.predict(X_test)
r2_train_score = r2_score(y_train, y_train_pred)
mae_train_score = median_absolute_error(y_train, y_train_pred)
r2_test_score = r2_score(y_test, y_test_pred)
mae_test_score = median_absolute_error(y_test, y_test_pred)
print('R2 score for training data: {} and for the test data: {}'.format(r2_train_score, r2_test_score))
print('Mean Absolute Error score for training data: {} and for the test data: {}'.format(mae_train_score, mae_test_score))