ISLP Package
Install ISLP Package
in a terminal: pip install ISLP
from ISLP import load_data
from ISLP.models import (ModelSpec as MS,
summarize,
poly)
Using Transformations: Fit and Transform
ModelSpec()
Ā (renamedĀMS()
Ā in the preamble) fromISLP
makes a transform objectfit()
may compute things as specified in the transform objecttransform()
applies fitted transformation to data array and produces the model matrixfit_transform()
combinesfit()
andtransform()
into one method. More complicated models benefit from the individual fit and transform stages being separated
design = MS(['column'])
design = design.fit(dataframe)
X = design.transform(dataframe)
-or-
design = MS(['column'])
X = design.fit_transform(dataframe)
summary()
method on a fitted model returns a full summary of the fitparams
attribute returns fitted coefficientsconf_int()
method can get CI of coefficientsget_prediction()
Ā method can be used for predictions
predictions = results.get_prediction(newXArray)
predictions.conf_int(alpha=0.05) #conf intervals
predictions.conf_int(obs=True, alpha=0.05) #pred intervals
Multivariate Goodness of Fit
results.rsquared
Ā gives usnp.sqrt(results.scale)
Ā gives us RSE- compute VIF using
variance_inflation_factor()
(renamedĀVIF()
Ā in the preamble)
List Comprehension
use a list comprehension to generate VIF for a list of variables X
in the model matrix:
vals = [VIF(X, i)
for i in range(1, X.shape[1])]
vif = pd.DataFrame({'vif':vals},
index=X.columns[1:])
could also construct vals
with a different for loop:
vals = []
for i in range(1, X.values.shape[1]):
vals.append(VIF(X.values, i))