from
sklearn.impute
import
SimpleImputer
import
numpy as np
X
=
np.array([[
1
,
2
, np.nan],
[
3
, np.nan,
4
],
[
5
,
6
, np.nan],
[
7
,
8
,
9
]])
Y
=
np.array([
14
,
20
,
29
,
40
])
print
(
'Check Null values \n'
,np.isnan(X))
imputer
=
SimpleImputer(strategy
=
'mean'
)
X_imputed
=
imputer.fit_transform(X)
from
sklearn.linear_model
import
LinearRegression
regressor
=
LinearRegression()
regressor.fit(X_imputed, Y)
print
(
'\nCoefficient :'
,regressor.coef_)
print
(
'Intercempt :'
,regressor.intercept_)
Y_pred
=
X_imputed @ regressor.coef_
+
regressor.intercept_
print
(
"Prediction :"
,Y_pred )