Model
This module contains classes and functions the basic FACSIMILE model.
model
Classes:
FACSIMILE
FACSIMILE(alphas: Tuple[float], fit_intercept: bool = True)
Bases: BaseEstimator
Predicts target scores from item responses using Lasso regression, producing a sparse model with a small number of items included.
Parameters:
-
alphas
Tuple[float]
) –Tuple of alpha values for each target variable.
-
fit_intercept
bool
, default:True
) –Whether to fit an intercept. Defaults to
True
.
Methods:
-
fit
–Fit the model to the data.
-
get_weights
–Return the classifier weights as a pandas dataframe.
-
plot_weights
–Plot a heatmap of classifier weights.
-
predict
–Predict the target scores for a given set of item responses.
-
predict_reduced
–Predict the target scores for a given set of item responses, using only
-
save
–Save the model to a file.
Source code in facsimile/model.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
fit
Fit the model to the data.
Parameters:
-
X
Union[DataFrame, ArrayLike]
) –Item responses. Can be provided as a dataframe or array of shape
(n_observations, n_items)
-
y
Union[DataFrame, ArrayLike]
) –Target scores. Can be provided as a dataframe or array of shape
(n_observations, n_targets)
Returns:
-
FACSIMILE
(BaseEstimator
) –The fitted model
Source code in facsimile/model.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
get_weights
get_weights(target_names: List[str] = None) -> DataFrame
Return the classifier weights as a pandas dataframe.
Parameters:
Returns:
-
DataFrame
–pd.DataFrame: A dataframe containing the classifier weights. Each row corresponds to an item, and each column to a target variable.
Source code in facsimile/model.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
plot_weights
plot_weights(cmap: str = 'viridis', colorbar_shrink: float = 1, colorbar_aspect: int = 5, figsize: tuple = None, vmin: float = None, vmax: float = None) -> None
Plot a heatmap of classifier weights.
Parameters:
-
data
DataFrame
) –The dataframe to plot.
-
cmap
str
, default:'viridis'
) –The colormap to use for the heatmap. Defaults to 'viridis'.
-
colorbar_shrink
float
, default:1
) –The size of the colorbar. Defaults to 1.
-
colorbar_aspect
int
, default:5
) –Aspect ratio of the colorbar. Defaults to 20.
-
figsize
tuple
, default:None
) –Figure size as (width, height). If None, a default size is determined based on the shape of the dataframe. Defaults to None.
-
vmin
float
, default:None
) –Minimum value for the colormap. Defaults to None.
-
vmax
float
, default:None
) –Maximum value for the colormap. Defaults
Source code in facsimile/model.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
predict
Predict the target scores for a given set of item responses.
Parameters:
-
X
Union[DataFrame, ArrayLike]
) –Item responses.
Returns:
-
DataFrame
–pd.DataFrame: Predicted target variable scores.
Source code in facsimile/model.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
predict_reduced
Predict the target scores for a given set of item responses, using only the items identified by the item reduction procedure.
Parameters:
-
X
Union[DataFrame, ArrayLike]
) –Responses for the items included in the item reduction procedure.
Returns:
-
DataFrame
–pd.DataFrame: Predicted target variable scores.
Source code in facsimile/model.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
save
Save the model to a file.
Parameters:
-
path
str
) –Path to save the model to.
Source code in facsimile/model.py
281 282 283 284 285 286 287 288 289 290 291 292 293 |
|