Unformatted text preview:

Names Brentyn Melton Sang Nyugen and Miguel Ibarra import numpy as np import pandas as pd import matplotlib pyplot as plt import sklearn metrics as metrics import seaborn as sns matplotlib inline from sklearn model selection import train test split from sklearn ensemble import RandomForestClassifier import tkinter as tk DataBase Acquisition df pd read excel r C Users brent Downloads concreteData xls df describe df info df head 5 class pandas core frame DataFrame RangeIndex 1030 entries 0 to 1029 Data columns total 9 columns Column Non Null Count Dtype 0 Cement component 1 kg in a m 3 mixture 1030 non null float64 1 Blast Furnace Slag component 2 kg in a m 3 mixture 1030 non null float64 2 Fly Ash component 3 kg in a m 3 mixture 1030 non null float64 3 Water component 4 kg in a m 3 mixture 1030 non null float64 4 Superplasticizer component 5 kg in a m 3 mixture 1030 non null float64 5 Coarse Aggregate component 6 kg in a m 3 mixture 1030 non null float64 6 Fine Aggregate component 7 kg in a m 3 mixture 1030 non null float64 7 Age day 1030 non null int64 8 Concrete compressive strength MPa megapascals 1030 non null float64 dtypes float64 8 int64 1 memory usage 72 5 KB Cement component 1 kg in a m 3 mixture Blast Furnace Slag component 2 kg in a m 3 mixture Fly Ash component 3 kg in a m 3 mixture Water component 4 kg in a m 3 mixture Superplasticizer component 5 kg in a m 3 mixture Coarse Aggregate component 6 kg in a m 3 mixture Fine Aggregate component 7 kg in a m 3 mixture Age day Concrete compressive strength MPa megapascals 540 0 540 0 332 5 332 5 198 6 0 0 0 0 142 5 142 5 132 4 0 0 0 0 0 0 0 0 0 0 1040 0 1055 0 932 0 932 0 978 4 676 0 676 0 594 0 594 0 825 5 28 28 270 365 360 79 986111 61 887366 40 269535 41 052780 44 296075 162 0 162 0 228 0 228 0 192 0 2 5 2 5 0 0 0 0 0 0 2 5 2 5 0 0 0 0 0 0 1040 0 1055 0 932 0 932 0 978 4 676 0 676 0 594 0 594 0 825 5 28 28 270 365 360 79 986111 61 887366 40 269535 41 052780 44 296075 df columns Cement Blast Furnace Slag Fly Ash Water SuperPlasticizer Coarse Aggregate Fine Aggregate df head Cement Blast Furnace Slag Fly Ash Water SuperPlasticizer Coarse Aggregate Fine Aggregate Age Concrete Strength 0 1 2 3 4 0 1 2 3 4 540 0 540 0 332 5 332 5 198 6 0 0 0 0 142 5 142 5 132 4 0 0 0 0 0 0 0 0 0 0 162 0 162 0 228 0 228 0 192 0 cement df Cement Blast Furnace Slag df Blast Furnace Slag Fly Ash df Fly Ash Water df Water SuperPlasticizer df SuperPlasticizer Coarse Aggregate df Coarse Aggregate Fine Aggregate df Fine Aggregate Age df Age Concrete Strength df Concrete Strength Data Model Structures Shows the correlation for all of the data sns heatmap df corr annot True AxesSubplot Data Model Fitting tools from sklearn model selection import train test split from sklearn preprocessing import StandardScaler x df iloc 1 y df iloc 1 seperate Data x train x test y train y test train test split x y test size 0 2 random state 2 StandardScalar StandardScaler Scale to have a standard deviation of 1 and the a mean of 0 x train StandardScalar fit transform x train x test StandardScalar transform x test from sklearn linear model import LinearRegression Lasso Ridge LR LinearRegression Lasso and Ridge Regression lasso Lasso ridge Ridge Training Data LR fit x train y train lasso fit x train y train ridge fit x train y train Predictions from test data y PredictionLinReg LR predict x test y predictionLasso lasso predict x test y predictionRidge ridge predict x test prints the RMSE and R2Score of Linear Regression LassoRegression RidgeRegression from sklearn metrics import mean squared error mean absolute error r2 score print Model RMSE R2 print LinearRegression t t t format np sqrt mean squared error y test y PredictionLinReg r2 score print LassoRegression t t t format np sqrt mean squared error y test y predictionLasso r2 score print RidgeRegression t t t format np sqrt mean squared error y test y predictionRidge r2 score Model RMSE R2 LinearRegression LassoRegression RidgeRegression 10 285045326177856 10 68337802861309 10 288679160592709 0 5700226130111653 0 5360722098905022 0 5697187266214931 plt scatter y PredictionLinReg y test s 20 plt plot y test min y test max y test min y test max k lw 2 plt xlabel predicted plt ylabel true plt title Linear Regression plt show plt scatter y predictionLasso y test s 20 plt plot y test min y test max y test min y test max k lw 2 plt xlabel predicted plt ylabel true plt title Lasso Regression plt show plt scatter y predictionRidge y test s 20 plt plot y test min y test max y test min y test max k lw 2 plt xlabel predicted plt ylabel true plt title Ridge Regression plt show from sklearn tree import DecisionTreeRegressor dtr DecisionTreeRegressor dtr fit x train y train y predictionDTR dtr predict x test plt scatter y test y predictionDTR s 20 plt plot y test min y test max y test min y test max k lw 2 plt xlabel predicted plt ylabel true plt title Decision Tree Regressor plt show from sklearn ensemble import RandomForestRegressor rfr RandomForestRegressor n estimators 200 rfr fit x train y train y predictionRFR rfr predict x test plt scatter y test y predictionRFR s 20 plt plot y test min y test max y test min y test max k lw 2 plt xlabel predicted plt ylabel true plt title Random Forest Regressor plt show models LR lasso ridge dtr rfr names Linear Regression Lasso Regression Ridge Regression Decision Tree Regressor Random Forest Regressor rmse for model in models rmse append np sqrt mean squared error y test model predict x test x np arange len names width 0 3 fig ax plt subplots figsize 10 7 rects ax bar x rmse width ax set ylabel RMSE ax set xlabel Models ax set title RMSE with different Regressions ax set xticks x ax set xticklabels names rotation 45 fig tight layout plt show Update Interface and implementation of the data frame from sklearn metrics import mean squared error mean absolute error r2 score df pd read excel r C Users brent Downloads concreteData xls df columns Cement Blast Furnace Slag Fly Ash Water SuperPlasticizer Coarse Aggregate Fine Aggregate df head 5 Cement Blast Furnace Slag Fly Ash Water SuperPlasticizer Coarse Aggregate Fine Aggregate Age Concrete Strength 0 1 2 3 4 540 0 540 0 332 5 332 5 198 6 0 0 0 0 142 5 142 5 132 4 0 0 …


View Full Document

TTU ENGR 1330 - Final Project Code

Documents in this Course
Load more
Download Final Project Code
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Final Project Code and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Final Project Code and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?