<jupyter_start><jupyter_text>Predicting Concrete Compressive Strength - Comparison with Linear Models In this code notebook, we will analyze the statistics pertaining the various models presented in this project. In the Exploratory Data Analysis notebook, we explored the various relationships that each consituent of concrete has on the cured compressive strength. The materials that held the strongest relationships, regardless of curing time, were cement, cementitious ratio, superplasticizer ratio, and fly ash ratio. We will examine each of the linear ratios independent of age, as well as at the industry-standard 28 day cure time mark.  Dataset Citation This dataset was retrieved from the UC Irvine Machine Learning Repository from the following URL: . The dataset was donated to the UCI Repository by Prof. <NAME> of Chung-Huah University, who retains copyright for the following published paper: <NAME>, "Modeling of strength of high performance concrete using artificial neural networks," Cement and Concrete Research, Vol. 28, No. 12, pp. 1797-1808 (1998). Additional papers citing this dataset are listed at the reference link above.  Import the Relevant Libraries<jupyter_code># Data Manipulation
import numpy as np
import pandas as pd

# Data Visualization
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
sns.set()

# Data Preprocessing
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler

# Linear Regresssion Model
from sklearn.linear_model import LinearRegression

# Model Evaluation
from sklearn.metrics import mean_squared_error,mean_absolute_error,explained_variance_score<jupyter_output><empty_output><jupyter_text>Import & Check the Data<jupyter_code>df1 = pd.read_csv('2020_1124_Modeling_Data.csv')
df2 = pd.read_csv('2020_1123_Concrete_Data_Loaded_Transformed.csv')

original_data = df1.copy()
transformed_data = df2.copy()
# The original data contains kg/m^3 values
original_data.head()
# Original data
original_data.describe()
# The transformed data contains ratios to total mass of the concrete mix
transformed_data.head()
# Transformed data
transformed_data.describe()<jupyter_output><empty_output><jupyter_text>Cement Modeling - Including All Cure Times We understand that the ratio of cement to compressive strength is linear. We will model this relationship in Python and evaluate its performance compared to our ANN model.  Visualization<jupyter_code># We will visualize the linear relationship between quantity of cement and compressive strength
cement = original_data['Cement']
strength = original_data['Compressive_Strength']
plt.scatter(cement,strength)<jupyter_output><empty_output><jupyter_text>Train the Linear Model<jupyter_code># Reshape the data so it complies with the linear model requirements
X = np.array(cement).reshape(1030,1)
y = np.array(strength).reshape(1030,1)
# Perform a train-test split 
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2,random_state=42)

# Train the linear model
lm = LinearRegression()
lm.fit(X_train,y_train)<jupyter_output><empty_output><jupyter_text>Test the Linear Model<jupyter_code>y_pred = lm.predict(X_test)<jupyter_output><empty_output><jupyter_text>Linear Equation<jupyter_code># print the intercept
print(lm.intercept_)
coeff = pd.DataFrame(lm.coef_,columns=['Coefficient'])
coeff<jupyter_output><empty_output><jupyter_text>Model Evaluation<jupyter_code># Plot the linear model preditions as a line superimposed on a scatter plot of the testing data
plt.scatter(X_test,y_test)
plt.plot(X_test,y_pred,'r')
# Evaluation Metrics
MAE_cement = mean_absolute_error(y_test, y_pred)
MSE_cement = mean_squared_error(y_test, y_pred)
RMSE_cement = np.sqrt(mean_squared_error(y_test, y_pred))

cement_stats = [MAE_cement,MSE_cement,RMSE_cement] # storing for model comparison at the end of this notebook

# Print the metrics
print(f"EVALUATION METRICS, LINEAR MODEL FOR CEMENT VS. COMPRESSIVE STRENGTH")
print('-----------------------------')
print(f"Mean Absolute Error (MAE):\t\t{MAE_cement}\nMean Squared Error:\t\t\t{MSE_cement}\nRoot Mean Squared Error (RMSE):\t\t{RMSE_cement}")
print('-----------------------------\n\n')<jupyter_output>EVALUATION METRICS, LINEAR MODEL FOR CEMENT VS. COMPRESSIVE STRENGTH
-----------------------------
Mean Absolute Error (MAE):		11.55561279863471
Mean Squared Error:			192.78479855432548
Root Mean Squared Error (RMSE):		13.884696559677689
-----------------------------<jupyter_text>Cement Modeling - 28 Day Cure Time We will model the cement vs compressive strength relationship for a constant cure time (28 days).  Visualization<jupyter_code># We will visualize the linear relationship between quantity of cement and compressive strength at 28 days
cement = original_data[original_data['Age']==28]['Cement']
strength = original_data[original_data['Age']==28]['Compressive_Strength']
plt.scatter(cement,strength)<jupyter_output><empty_output><jupyter_text>Train the Linear Model<jupyter_code># Reshape the data so it complies with the linear model requirements
X = np.array(cement).reshape(425,1)
y = np.array(strength).reshape(425,1)
# Perform a train-test split 
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2,random_state=42)

# Train the linear model
lm = LinearRegression()
lm.fit(X_train,y_train)<jupyter_output><empty_output><jupyter_text>Test the Linear Model<jupyter_code>y_pred = lm.predict(X_test)<jupyter_output><empty_output><jupyter_text>Linear Equation<jupyter_code># print the intercept
print(lm.intercept_)
coeff = pd.DataFrame(lm.coef_,columns=['Coefficient'])
coeff<jupyter_output><empty_output><jupyter_text>Model Evaluation<jupyter_code># Plot the linear model preditions as a line superimposed on a scatter plot of the testing data
plt.scatter(X_test,y_test)
plt.plot(X_test,y_pred,'r')
# Evaluation Metrics
MAE_cement_28 = mean_absolute_error(y_test, y_pred)
MSE_cement_28 = mean_squared_error(y_test, y_pred)
RMSE_cement_28 = np.sqrt(mean_squared_error(y_test, y_pred))

cement_28_stats = [MAE_cement_28,MSE_cement_28,RMSE_cement_28] # storing for model comparison at the end of this notebook

# Print the metrics
print(f"EVALUATION METRICS, LINEAR MODEL FOR CEMENT VS. COMPRESSIVE STRENGTH")
print('-----------------------------')
print(f"Mean Absolute Error (MAE):\t\t{MAE_cement_28}\nMean Squared Error:\t\t\t{MSE_cement_28}\nRoot Mean Squared Error (RMSE):\t\t{RMSE_cement_28}")
print('-----------------------------\n\n')<jupyter_output>EVALUATION METRICS, LINEAR MODEL FOR CEMENT VS. COMPRESSIVE STRENGTH
-----------------------------
Mean Absolute Error (MAE):		9.134081632197555
Mean Squared Error:			140.11750347700305
Root Mean Squared Error (RMSE):		11.837123952928899
-----------------------------<jupyter_text>Cementitious Ratio Modeling - Including All Cure Times We know that the ratio of cementitious materials to the total mass is (cement + fly ash)/(total mass) to compressive strength is linear. We will model this relationship in Python and evaluate its performance.  Visualization<jupyter_code># We will visualize the linear relationship between quantity of cementitious materials and compressive strength
cementitious = transformed_data['Cementitious_Ratio']
strength = transformed_data['Compressive_Strength']
plt.scatter(cementitious,strength)<jupyter_output><empty_output><jupyter_text>Train the Linear Model<jupyter_code># Reshape the data so it complies with the linear model requirements
X = np.array(cementitious).reshape(1030,1)
y = np.array(strength).reshape(1030,1)
# Perform a train-test split 
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2,random_state=42)

# Train the linear model
lm = LinearRegression()
lm.fit(X_train,y_train)<jupyter_output><empty_output><jupyter_text>Test the Linear Model<jupyter_code>y_pred = lm.predict(X_test)<jupyter_output><empty_output><jupyter_text>Linear Equation<jupyter_code># print the intercept
print(lm.intercept_)
coeff = pd.DataFrame(lm.coef_,columns=['Coefficient'])
coeff<jupyter_output><empty_output><jupyter_text>Model Evaluation<jupyter_code># Plot the linear model preditions as a line superimposed on a scatter plot of the testing data
plt.scatter(X_test,y_test)
plt.plot(X_test,y_pred,'r')
# Evaluation Metrics
MAE_cementitious = mean_absolute_error(y_test, y_pred)
MSE_cementitious = mean_squared_error(y_test, y_pred)
RMSE_cementitious = np.sqrt(mean_squared_error(y_test, y_pred))

cementitious_stats = [MAE_cementitious,MSE_cementitious,RMSE_cementitious] # storing for model comparison at the end of this notebook

# Print the metrics
print(f"EVALUATION METRICS, LINEAR MODEL FOR CEMENTITIOUS RATIO VS. COMPRESSIVE STRENGTH")
print('-----------------------------')
print(f"Mean Absolute Error (MAE):\t\t{MAE_cementitious}\nMean Squared Error:\t\t\t{MSE_cementitious}\nRoot Mean Squared Error (RMSE):\t\t{RMSE_cementitious}")
print('-----------------------------\n\n')<jupyter_output>EVALUATION METRICS, LINEAR MODEL FOR CEMENTITIOUS RATIO VS. COMPRESSIVE STRENGTH
-----------------------------
Mean Absolute Error (MAE):		12.834672509172698
Mean Squared Error:			253.05814774985234
Root Mean Squared Error (RMSE):		15.907801474429217
-----------------------------<jupyter_text>Cementitious Ratio Modeling - 28 Day Cure Time  Visualization<jupyter_code># We will visualize the linear relationship between quantity of cementitious materials and compressive strength at 28 days
cementitious = transformed_data[original_data['Age']==28]['Cementitious_Ratio']
strength = transformed_data[original_data['Age']==28]['Compressive_Strength']
plt.scatter(cementitious,strength)<jupyter_output><empty_output><jupyter_text>Train the Linear Model<jupyter_code># Reshape the data so it complies with the linear model requirements
X = np.array(cementitious).reshape(425,1)
y = np.array(strength).reshape(425,1)
# Perform a train-test split 
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2,random_state=42)

# Train the linear model
lm = LinearRegression()
lm.fit(X_train,y_train)<jupyter_output><empty_output><jupyter_text>Test the Linear Model<jupyter_code>y_pred = lm.predict(X_test)<jupyter_output><empty_output><jupyter_text>Linear Equation<jupyter_code># print the intercept
print(lm.intercept_)
coeff = pd.DataFrame(lm.coef_,columns=['Coefficient'])
coeff<jupyter_output><empty_output><jupyter_text>Model Evaluation<jupyter_code># Plot the linear model preditions as a line superimposed on a scatter plot of the testing data
plt.scatter(X_test,y_test)
plt.plot(X_test,y_pred,'r')
# Evaluation Metrics
MAE_cementitious_28 = mean_absolute_error(y_test, y_pred)
MSE_cementitious_28 = mean_squared_error(y_test, y_pred)
RMSE_cementitious_28 = np.sqrt(mean_squared_error(y_test, y_pred))

cementitious_28_stats = [MAE_cementitious_28,MSE_cementitious_28,RMSE_cementitious_28] # storing for model comparison at the end of this notebook

# Print the metrics
print(f"EVALUATION METRICS, LINEAR MODEL FOR CEMENTITIOUS RATIO VS. COMPRESSIVE STRENGTH AT 28 DAYS")
print('-----------------------------')
print(f"Mean Absolute Error (MAE):\t\t{MAE_cementitious_28}\nMean Squared Error:\t\t\t{MSE_cementitious_28}\nRoot Mean Squared Error (RMSE):\t\t{RMSE_cementitious_28}")
print('-----------------------------\n\n')<jupyter_output>EVALUATION METRICS, LINEAR MODEL FOR CEMENTITIOUS RATIO VS. COMPRESSIVE STRENGTH AT 28 DAYS
-----------------------------
Mean Absolute Error (MAE):		11.519580245958837
Mean Squared Error:			197.95720060481753
Root Mean Squared Error (RMSE):		14.069726386991949
-----------------------------<jupyter_text>Fly Ash Ratio Modeling - Including All Cure Times The fly ash ratio is interpreted as the percentage of fly ash within the cementitious materials mix, that is, Fly_Ash_Ratio = (fly ash + cement)/(total mass).  Visualization<jupyter_code># We will visualize the linear relationship between fly ash ratio and compressive strength
fly = transformed_data['Fly_Ash_Ratio']
strength = transformed_data['Compressive_Strength']
plt.scatter(fly,strength)<jupyter_output><empty_output><jupyter_text>Data Preprocessing We see from the graph above that there are many instances where there is no fly ash in the mix design. Let us use only nonzero entries for our analysis.<jupyter_code>fly = transformed_data[transformed_data['Fly_Ash_Ratio']!=0]['Fly_Ash_Ratio']
strength = transformed_data[transformed_data['Fly_Ash_Ratio']!=0]['Compressive_Strength']
plt.scatter(fly,strength)<jupyter_output><empty_output><jupyter_text>Train the Linear Model<jupyter_code># Reshape the data so it complies with the linear model requirements
X = np.array(fly).reshape(464,1)
y = np.array(strength).reshape(464,1)
# Perform a train-test split 
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2,random_state=42)

# Train the linear model
lm = LinearRegression()
lm.fit(X_train,y_train)<jupyter_output><empty_output><jupyter_text>Test the Linear Model<jupyter_code>y_pred = lm.predict(X_test)<jupyter_output><empty_output><jupyter_text>Linear Equation<jupyter_code># print the intercept
print(lm.intercept_)
coeff = pd.DataFrame(lm.coef_,columns=['Coefficient'])
coeff<jupyter_output><empty_output><jupyter_text>Model Evaluation<jupyter_code># Plot the linear model preditions as a line superimposed on a scatter plot of the testing data
plt.scatter(X_test,y_test)
plt.plot(X_test,y_pred,'r')
# Evaluation Metrics
MAE_fly = mean_absolute_error(y_test, y_pred)
MSE_fly = mean_squared_error(y_test, y_pred)
RMSE_fly = np.sqrt(mean_squared_error(y_test, y_pred))

fly_stats = [MAE_fly,MSE_fly,RMSE_fly] # storing for model comparison at the end of this notebook

# Print the metrics
print(f"EVALUATION METRICS, LINEAR MODEL FOR FLY ASH RATIO VS. COMPRESSIVE STRENGTH")
print('-----------------------------')
print(f"Mean Absolute Error (MAE):\t\t{MAE_fly}\nMean Squared Error:\t\t\t{MSE_fly}\nRoot Mean Squared Error (RMSE):\t\t{RMSE_fly}")
print('-----------------------------\n\n')<jupyter_output>EVALUATION METRICS, LINEAR MODEL FOR FLY ASH RATIO VS. COMPRESSIVE STRENGTH
-----------------------------
Mean Absolute Error (MAE):		12.121987321537818
Mean Squared Error:			212.8943249027957
Root Mean Squared Error (RMSE):		14.590898700998363
-----------------------------<jupyter_text>Fly Ash Ratio Modeling - 28 Day Cure Time The fly ash ratio is interpreted as the percentage of fly ash within the cementitious materials mix, that is, Fly_Ash_Ratio = (fly ash + cement)/(total mass).<jupyter_code>fly = transformed_data[((transformed_data['Fly_Ash_Ratio']!=0)&(transformed_data['Age']==28))]['Fly_Ash_Ratio']
strength = transformed_data[((transformed_data['Fly_Ash_Ratio']!=0)&(transformed_data['Age']==28))]['Compressive_Strength']
plt.scatter(fly,strength)<jupyter_output><empty_output><jupyter_text>Train the Linear Model<jupyter_code># Reshape the data so it complies with the linear model requirements
X = np.array(fly).reshape(217,1)
y = np.array(strength).reshape(217,1)
# Perform a train-test split 
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2,random_state=42)

# Train the linear model
lm = LinearRegression()
lm.fit(X_train,y_train)<jupyter_output><empty_output><jupyter_text>Test the Linear Model<jupyter_code>y_pred = lm.predict(X_test)<jupyter_output><empty_output><jupyter_text>Linear Equation<jupyter_code># print the intercept
print(lm.intercept_)
coeff = pd.DataFrame(lm.coef_,columns=['Coefficient'])
coeff<jupyter_output><empty_output><jupyter_text>Model Evaluation<jupyter_code># Plot the linear model preditions as a line superimposed on a scatter plot of the testing data
plt.scatter(X_test,y_test)
plt.plot(X_test,y_pred,'r')
# Evaluation Metrics
MAE_fly_28 = mean_absolute_error(y_test, y_pred)
MSE_fly_28 = mean_squared_error(y_test, y_pred)
RMSE_fly_28 = np.sqrt(mean_squared_error(y_test, y_pred))

fly_28_stats = [MAE_fly_28,MSE_fly_28,RMSE_fly_28] # storing for model comparison at the end of this notebook

# Print the metrics
print(f"EVALUATION METRICS, LINEAR MODEL FOR FLY ASH RATIO VS. COMPRESSIVE STRENGTH AT 28 DAYS")
print('-----------------------------')
print(f"Mean Absolute Error (MAE):\t\t{MAE_fly_28}\nMean Squared Error:\t\t\t{MSE_fly_28}\nRoot Mean Squared Error (RMSE):\t\t{RMSE_fly_28}")
print('-----------------------------\n\n')<jupyter_output>EVALUATION METRICS, LINEAR MODEL FOR FLY ASH RATIO VS. COMPRESSIVE STRENGTH AT 28 DAYS
-----------------------------
Mean Absolute Error (MAE):		7.692694771235926
Mean Squared Error:			91.3179595195656
Root Mean Squared Error (RMSE):		9.556043089038768
-----------------------------<jupyter_text>Superplasticizer Ratio Modeling - Including All Cure Times The superplasticizer ratio is the ratio of superplasticizer contained within the total mix design, by weight.  Visualization<jupyter_code># We will visualize the linear relationship between superplasticizer ratio and compressive strength
superplasticizer = transformed_data['Superplasticizer_Ratio']
strength = transformed_data['Compressive_Strength']
plt.scatter(superplasticizer,strength)<jupyter_output><empty_output><jupyter_text>Data Preprocessing Once agaain, we see from the graph above that there are many instances where there is no superplasticizer in the mix design. Let us use only nonzero entries for our analysis.<jupyter_code>superplasticizer = transformed_data[transformed_data['Superplasticizer_Ratio']!=0]['Superplasticizer_Ratio']
strength = transformed_data[transformed_data['Superplasticizer_Ratio']!=0]['Compressive_Strength']
plt.scatter(superplasticizer,strength)<jupyter_output><empty_output><jupyter_text>This is better, but we see a large spread in the data. Let's remove any outliers first, before training our model.<jupyter_code>superplasticizer.describe()
mean = 0.004146
three_sigma = 3*0.001875
upper = mean + three_sigma
lower = mean - three_sigma

print(f"The lower bound is:\t{lower}\nThe upper bound is:\t{upper}")<jupyter_output>The lower bound is:	-0.0014789999999999994
The upper bound is:	0.009771<jupyter_text>Since there are no negative ratios, we only need to remove data points where the superplasticizer ratio is greater than 0.009771.<jupyter_code>superplasticizer = transformed_data[transformed_data['Superplasticizer_Ratio']!=0][transformed_data['Superplasticizer_Ratio'] < upper]['Superplasticizer_Ratio']
strength = transformed_data[transformed_data['Superplasticizer_Ratio']!=0][transformed_data['Superplasticizer_Ratio'] < upper]['Compressive_Strength']
plt.scatter(superplasticizer,strength)<jupyter_output><ipython-input-60-1ad850f1b580>:1: UserWarning: Boolean Series key will be reindexed to match DataFrame index.
  superplasticizer = transformed_data[transformed_data['Superplasticizer_Ratio']!=0][transformed_data['Superplasticizer_Ratio'] < upper]['Superplasticizer_Ratio']
<ipython-input-60-1ad850f1b580>:2: UserWarning: Boolean Series key will be reindexed to match DataFrame index.
  strength = transformed_data[transformed_data['Superplasticizer_Ratio']!=0][transformed_data['Superplasticizer_Ratio'] < upper]['Compressive_Strength']<jupyter_text>Train the Linear Model<jupyter_code># We will train and test our model only on the data above, that does not contain outliers
# Reshape the data so it complies with the linear model requirements
X = np.array(superplasticizer).reshape(641,1)
y = np.array(strength).reshape(641,1)
# Perform a train-test split 
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2,random_state=42)

# Train the linear model
lm = LinearRegression()
lm.fit(X_train,y_train)<jupyter_output><empty_output><jupyter_text>Test the Linear Model<jupyter_code>y_pred = lm.predict(X_test)<jupyter_output><empty_output><jupyter_text>Linear Equation<jupyter_code># print the intercept
print(lm.intercept_)
coeff = pd.DataFrame(lm.coef_,columns=['Coefficient'])
coeff<jupyter_output><empty_output><jupyter_text>Model Evaluation<jupyter_code># Plot the linear model preditions as a line superimposed on a scatter plot of the testing data
plt.scatter(X_test,y_test)
plt.plot(X_test,y_pred,'r')
# Evaluation Metrics
MAE_super = mean_absolute_error(y_test, y_pred)
MSE_super = mean_squared_error(y_test, y_pred)
RMSE_super = np.sqrt(mean_squared_error(y_test, y_pred))

super_stats = [MAE_super,MSE_super,RMSE_super] # storing for model comparison at the end of this notebook

# Print the metrics
print(f"EVALUATION METRICS, LINEAR MODEL FOR SUPERPLASTICIZER RATIO VS. COMPRESSIVE STRENGTH")
print('-----------------------------')
print(f"Mean Absolute Error (MAE):\t\t{MAE_super}\nMean Squared Error:\t\t\t{MSE_super}\nRoot Mean Squared Error (RMSE):\t\t{RMSE_super}")
print('-----------------------------\n\n')<jupyter_output>EVALUATION METRICS, LINEAR MODEL FOR SUPERPLASTICIZER RATIO VS. COMPRESSIVE STRENGTH
-----------------------------
Mean Absolute Error (MAE):		12.189766983759341
Mean Squared Error:			225.90929843844432
Root Mean Squared Error (RMSE):		15.030279386573103
-----------------------------<jupyter_text>Superplasticizer Ratio Modeling - 28 Day Cure Time The superplasticizer ratio is the ratio of superplasticizer contained within the total mix design, by weight.  Visualization<jupyter_code>superplasticizer = transformed_data[((transformed_data['Superplasticizer_Ratio']!=0)&(transformed_data['Age']==28))]['Superplasticizer_Ratio']
strength = transformed_data[((transformed_data['Superplasticizer_Ratio']!=0)&(transformed_data['Age']==28))]['Compressive_Strength']
plt.scatter(superplasticizer,strength)<jupyter_output><empty_output><jupyter_text>This is better, but we see a large spread in the data. Let's remove any outliers first, before training our model.<jupyter_code>superplasticizer.describe()
mean = 0.004146
three_sigma = 3*0.001875
upper = mean + three_sigma
lower = mean - three_sigma

print(f"The lower bound is:\t{lower}\nThe upper bound is:\t{upper}")<jupyter_output>The lower bound is:	-0.0014789999999999994
The upper bound is:	0.009771<jupyter_text>Since there are no negative ratios, we only need to remove data points where the superplasticizer ratio is greater than 0.009771.<jupyter_code>superplasticizer = transformed_data[((transformed_data['Superplasticizer_Ratio']!=0)&(transformed_data['Age']==28)&(transformed_data['Superplasticizer_Ratio']<upper))]['Superplasticizer_Ratio']
strength = transformed_data[((transformed_data['Superplasticizer_Ratio']!=0)&(transformed_data['Age']==28)&(transformed_data['Superplasticizer_Ratio']<upper))]['Compressive_Strength']
plt.scatter(superplasticizer,strength)<jupyter_output><empty_output><jupyter_text>Train the Linear Model<jupyter_code># We will train and test our model only on the data above, that does not contain outliers
# Reshape the data so it complies with the linear model requirements
X = np.array(superplasticizer).reshape(315,1)
y = np.array(strength).reshape(315,1)
# Perform a train-test split 
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.2,random_state=42)

# Train the linear model
lm = LinearRegression()
lm.fit(X_train,y_train)<jupyter_output><empty_output><jupyter_text>Test the Linear Model<jupyter_code>y_pred = lm.predict(X_test)<jupyter_output><empty_output><jupyter_text>Linear Equation<jupyter_code># print the intercept
print(lm.intercept_)
coeff = pd.DataFrame(lm.coef_,columns=['Coefficient'])
coeff<jupyter_output><empty_output><jupyter_text>Model Evaluation<jupyter_code># Plot the linear model preditions as a line superimposed on a scatter plot of the testing data
plt.scatter(X_test,y_test)
plt.plot(X_test,y_pred,'r')
# Evaluation Metrics
MAE_super_28 = mean_absolute_error(y_test, y_pred)
MSE_super_28 = mean_squared_error(y_test, y_pred)
RMSE_super_28 = np.sqrt(mean_squared_error(y_test, y_pred))

super_stats_28 = [MAE_super_28,MSE_super_28,RMSE_super_28] # storing for model comparison at the end of this notebook

# Print the metrics
print(f"EVALUATION METRICS, LINEAR MODEL FOR SUPERPLASTICIZER RATIO VS. COMPRESSIVE STRENGTH AT 28 DAYS")
print('-----------------------------')
print(f"Mean Absolute Error (MAE):\t\t{MAE_super_28}\nMean Squared Error:\t\t\t{MSE_super_28}\nRoot Mean Squared Error (RMSE):\t\t{RMSE_super_28}")
print('-----------------------------\n\n')<jupyter_output>EVALUATION METRICS, LINEAR MODEL FOR SUPERPLASTICIZER RATIO VS. COMPRESSIVE STRENGTH AT 28 DAYS
-----------------------------
Mean Absolute Error (MAE):		11.954354128234902
Mean Squared Error:			243.9703785891613
Root Mean Squared Error (RMSE):		15.619551164779393
-----------------------------<jupyter_text>Model Comparisons Analysis Neither superplasticizer linear model appeared to represent the data well from a visual perspective. The cement, cementitious ratio, and fly ash ratio linear models, however, did. We can display all of the evaluation metrics below and compare them to the artificial neural network's (ANN) performance.<jupyter_code>ANN_metrics = [5.083552,6.466492**2,6.466492]

metrics = [cement_stats, cementitious_stats, fly_stats, super_stats, ANN_metrics]
metrics_28 = [cement_28_stats, cementitious_28_stats, fly_28_stats, super_stats_28, ANN_metrics]

metrics_df = pd.DataFrame(data=metrics, index=['Cement (Ignoring Cure Time)','Cementitious_Ratio (Ignoring Cure Time)','Fly_Ash_Ratio (Ignoring Cure Time)','Superplasticizer_Ratio (Ignoring Cure Time)','ANN (Function of Time)'], columns=['MAE','MSE','RMSE'])
metrics_28_df = pd.DataFrame(data=metrics_28, index=['Cement (Cure Time = 28 Days)','Cementitious_Ratio (Cure Time = 28 Days)','Fly_Ash_Ratio (Cure Time = 28 Days)','Superplasticizer_Ratio (Cure Time = 28 Days)','ANN (Function of Time)'], columns=['MAE','MSE','RMSE'])
metrics_df
metrics_28_df<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12849684407387205, 'fraction_numerical': 0.03292293306319645, 'mean_word_length': 5.993732970027248, 'pattern_counts': {'":': 0, '<': 196, '<?xml version=': 0, '>': 190, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '49', 'dir': 'jupyter-structured-clean-dedup', 'id': '14201', 'license': 'Apache-2.0', 'n_tokens_mistral': 9405, 'n_tokens_neox': 8311, 'n_words': 2095, 'path': '02_Python_Code/03_Model_Analysis/2020_1125_Comparison_with_Linear_Models.ipynb', 'repo_name': 'ericdhitchens/Predicting_Concrete_Compressive_Strength', 'size': '25676'}