Model

class hhpy.modelling.Model(model: object = None, name: str = 'pred', X_ref: Union[Sequence[T_co], str] = None, y_ref: Union[Sequence[T_co], str] = None)[source]

Bases: hhpy.modelling._BaseModel

A unified modeling class that is extended from sklearn, accepts any model that implements .fit and .predict

Parameters:
  • model – Any model object that implements .fit and .predict
  • name – Name of the model, used for naming columns [optional]
  • X_ref – List of features (predictors) used for training the model
  • y_ref – List of labels (targets) to be predicted

Methods Summary

fit(X, Sequence[T_co], str] = None, y, …) generalized fit method extending on model.fit
predict([X, df, return_type]) Generalized predict method based on model.predict

Methods Documentation

fit(X: Union[numpy.ndarray, Sequence[T_co], str] = None, y: Union[numpy.ndarray, Sequence[T_co], str] = None, df: pandas.core.frame.DataFrame = None, dropna: bool = True, X_test: Union[numpy.ndarray, Sequence[T_co], str] = None, y_test: Union[numpy.ndarray, Sequence[T_co], str] = None, df_test: pandas.core.frame.DataFrame = None) → None[source]

generalized fit method extending on model.fit

Parameters:
  • X – The feature (predictor) data used for training as DataFrame, np.array or column names
  • y – The label (target) data used for training as DataFrame, np.array or column names
  • df – Pandas DataFrame containing the training data, optional if array like data is passed for X/y
  • dropna – Whether to drop rows containing NA in the training data [optional]
  • X_test – The feature (predictor) data used for testing as DataFrame, np.array or column names
  • y_test – The label (target) data used for testing as DataFrame, np.array or column names
  • df_test – Pandas DataFrame containing the testing data, optional if array like data is passed for X/y test
Returns:

None

predict(X=None, df=None, return_type='y') → Union[pandas.core.series.Series, pandas.core.frame.DataFrame][source]

Generalized predict method based on model.predict

Parameters:
  • X – The feature (predictor) data used for training as DataFrame, np.array or column names
  • df – Pandas DataFrame containing the training and testing data. Can be saved to the Model object or supplied on an as needed basis.
  • return_type – one of [‘y’, ‘df’, ‘DataFrame’], if ‘y’ returns a pandas Series / DataFrame with only the predictions, if one of ‘df’,’DataFrame’ returns the full DataFrame with predictions added
Returns:

see return_type