Импорт файлов библиотеки
%matplotlib inline
импортировать numpy как np
%matplotlib inline
импортировать numpy как np
импортировать pandas как pd
из sklearn.model_selection import train_test_split
import matplotlib .pyplot as plt
из sklearn.utils import shuffle
import seaborn as sns
import matplotlib.gridspec as gridspec
from sklearn.preprocessing import StandardScaler
from sklearn import metrics
%matplotlib inline
из sklearn.metrics import mean_squared_error
Прочитайте данные (файл MaterialProperties1.csv вверху страницы.
df = pd.read_csv('MaterialProperties1.csv')
Подсчитайте общее количество материалов
print(" # Общее количество материалов: " + str(len(df.index)))
# Total No of Materials: 211
Получите информацию из набора данных о том, сколько нулевых значений существует.
df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 211 entries, 0 to 210 Data columns (total 15 columns): Materials 211 non-null object Density 211 non-null float64 Brinell 175 non-null object Tensile Strength ultimate 200 non-null float64 Yield Strength 139 non-null float64 Modulus of Elasticity 193 non-null float64 Poisson's Ratio 157 non-null float64 %Elongation at break 168 non-null float64 %Reduction of area 40 non-null float64 Izod Impact J 65 non-null float64 Fracture Toughness Mpa(m)^0.5 29 non-null float64 Thermal conductivity W/m-K 174 non-null float64 Specific Heat Cpacity J/g-K 144 non-null float64 Coefficient of thermal expansion 1E-6/K 188 non-null float64 Electrical Resistivity Ohm-cm 193 non-null float64 dtypes: float64(13), object(2) memory usage: 24.9+ KB
df.isnull()
Всего нулевых значений в каждом предмете
df.isnull().сумма()
Materials 0 Density 0 Brinell 36 Tensile Strength \nultimate 11 Yield Strength 72 Modulus of Elasticity\n 18 Poisson's Ratio 54 %Elongation at break 43 %Reduction of area 171 Izod Impact\nJ 146 Fracture Toughness\nMpa(m)^0.5 182 Thermal conductivity\nW/m-K 37 Specific Heat Cpacity\nJ/g-K 67 Coefficient of thermal expansion\n1E-6/K 23 Electrical Resistivity\nOhm-cm 18 dtype: int64
sns.heatmap(df.isnull(),yticklabels=False)
sns.heatmap(df.isnull(), yticklabels=False, cbar=False)
df.isnull().сумма()
Materials 0 Density 0 Brinell 0 Tensile Strength \nultimate 0 Yield Strength 0 Modulus of Elasticity\n 0 Poisson's Ratio 0 %Elongation at break 0 %Reduction of area 0 Izod Impact\nJ 0 Thermal conductivity\nW/m-K 0 Specific Heat Cpacity\nJ/g-K 0 Coefficient of thermal expansion\n1E-6/K 0 Electrical Resistivity\nOhm-cm 0 dtype: int64
df.drop(["Материалы"], ось=1, inplace=Истина)
df.drop(["Удельная теплоемкость\nJ/g-K", "Плотность", "%Уменьшение площади"], axis=1, inplace=True)
df.drop(["Коэффициент теплового расширения\n1E-6/K"], axis=1, inplace=True)
df.drop(["Удельное электрическое сопротивление\nОм-см"], axis=1, inplace=True)
x=df.drop("Предел текучести", axis=1)
y=df["Предел текучести"]
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0,3, random_state=1)
соответствовать модели линейной регрессии
logmodel = LinearRegression()
logmodel.fit(x_train, y_train)
print('\nКоэффициент модели :', logmodel.coef_)
Coefficient of model : [ 0.65159562 -4.54639136 -0.80161513 0.81854356 1.69816966]
print('\nПерехват модели',logmodel.intercept_)
Intercept of model 796.281445592086
Predict_train = logmodel.predict(x_train)
print('Предел текучести',predict_train)
Yield Strength [322.05317733 323.49592678 305.5774393 545.13474166 331.36765484 425.86675548 366.07224481 450.4217144 374.18578391 658.26547434 393.55656412 396.00252302]
rmse_train = mean_squared_error(y_train,predict_train)**(0,5)
print('\nRMSE в наборе данных поезда: ‘, rmse_train)
RMSE on train dataset : 16.742784606918722
Predict_test = logmodel.predict(x_test)
print('Предел текучести',predict_test)
Yield Strength [518.38811453 342.90543881 449.3886888 386.81086662 778.50233868 606.2861823 ]
rmse_test = mean_squared_error(y_test,predict_test)**(0.5)
print('\nRMSE для тестового набора данных: ‘, rmse_test)
RMSE on test dataset : 81.95139576961179