def partial_fit(self, df, options): # Make a copy of data, to not alter original dataframe X = df.copy() X, _, columns = df_util.prepare_features(X, self.feature_variables) if self.columns is not None: df_util.handle_new_categorical_values(X, None, options, self.columns) if X.empty: return else: self.columns = columns self.estimator.partial_fit(X)
def partial_fit(self, df, options): # Handle backwards compatibility. add_missing_attr(self.estimator, attr='max_iter', value=5, param_key='n_iter') add_missing_attr(self.estimator, attr='tol', value=None) # Make a copy of data, to not alter original dataframe X = df.copy() relevant_variables = self.feature_variables + [self.target_variable] X, y, columns = df_util.prepare_features_and_target( X=X, variables=relevant_variables, target=self.target_variable, mlspl_limits=options.get('mlspl_limits'), ) if self.columns is not None: X, y = df_util.handle_new_categorical_values( X, y, options, self.columns) if X.empty: return else: self.columns = columns self.scaler.partial_fit(X.values) scaled_X = self.scaler.transform(X.values) self.estimator.partial_fit(scaled_X, y) cexc.messages.warn('n_iter is set to 1 when partial fit is performed')
def partial_fit(self, df, options): # Make a copy of data, to not alter original dataframe X = df.copy() algo_util.assert_estimator_supports_partial_fit(self.estimator) X, _, columns = df_util.prepare_features( X=X, variables=self.feature_variables, mlspl_limits=options.get('mlspl_limits'), ) if getattr(self, 'columns', None): df_util.handle_new_categorical_values(X, None, options, self.columns) if X.empty: return else: self.columns = columns self.estimator.partial_fit(X)
def partial_fit(self, df, options): # Handle backwards compatibility. add_missing_attr(self.estimator, attr='max_iter', value=5, param_key='n_iter') add_missing_attr(self.estimator, attr='tol', value=None) # Check target variable df[self.target_variable] = df_util.check_and_convert_target_variable( df, self.target_variable) # Make a copy of data, to not alter original dataframe X = df.copy() relevant_variables = self.feature_variables + [self.target_variable] mlspl_limits = options.get('mlspl_limits', {}) max_classes = int( mlspl_limits.get('max_distinct_cat_values_for_classifier', 100)) df_util.limit_classes_for_classifier(X, self.target_variable, max_classes) X, y, columns = df_util.prepare_features_and_target( X=X, variables=relevant_variables, target=self.target_variable, mlspl_limits=mlspl_limits, ) if self.classes is None: self.classes = np.unique(y) scaled_X = self.scaler.fit_transform(X.values) self.estimator.partial_fit(scaled_X, y, classes=self.classes) self.columns = columns else: X, y = df_util.handle_new_categorical_values( X, y, options, self.columns, self.classes) if X.empty: return self.scaler.partial_fit(X.values) scaled_X = self.scaler.transform(X.values) self.estimator.partial_fit(scaled_X, y)
def partial_fit(self, df, options): # Check target variable df[self.target_variable] = df_util.check_and_convert_target_variable( df, self.target_variable) # Make a copy of data, to not alter original dataframe X = df.copy() # Ensure that partial_fit method is defined for the estimator algo_util.assert_estimator_supports_partial_fit(self.estimator) # Ensure there aren't too many classes mlspl_limits = options.get('mlspl_limits', {}) max_classes = int( mlspl_limits.get('max_distinct_cat_values_for_classifiers', 100)) df_util.limit_classes_for_classifier(X, self.target_variable, max_classes) # Use all the variables used_variables = self.feature_variables + [self.target_variable] # Prepare the dataset X, y, columns = df_util.prepare_features_and_target( X=X, variables=used_variables, target=self.target_variable, mlspl_limits=mlspl_limits, ) # On the very first partial call if self.classes is None: self.classes = np.unique(y) self.estimator.partial_fit(X.values, y.values, self.classes) self.columns = columns # On subsequent partial_fit calls else: X, y = df_util.handle_new_categorical_values( X, y, options, self.columns, self.classes) if not X.empty: self.estimator.partial_fit(X.values, y.values)
def partial_fit(self, df, options): # Make a copy of data, to not alter original dataframe X = df.copy() relevant_variables = self.feature_variables + [self.target_variable] X, y, columns = df_util.prepare_features_and_target( X=X, variables=relevant_variables, target=self.target_variable, ) if self.columns is not None: X, y = df_util.handle_new_categorical_values( X, y, options, self.columns) if X.empty: return else: self.columns = columns self.scaler.partial_fit(X.values) scaled_X = self.scaler.transform(X.values) self.estimator.partial_fit(scaled_X, y) cexc.messages.warn('n_iter is set to 1 when partial fit is performed')
def partial_fit(self, df, options): # Make a copy of data, to not alter original dataframe X = df.copy() relevant_variables = self.feature_variables + [self.target_variable] df_util.limit_classes_for_classifier(X, self.target_variable) X, y, columns = df_util.prepare_features_and_target( X=X, variables=relevant_variables, target=self.target_variable, ) if self.classes is None: self.classes = np.unique(y) scaled_X = self.scaler.fit_transform(X.values) self.estimator.partial_fit(scaled_X, y, classes=self.classes) self.columns = columns else: X, y = df_util.handle_new_categorical_values(X, y, options, self.columns, self.classes) if X.empty: return self.scaler.partial_fit(X.values) scaled_X = self.scaler.transform(X.values) self.estimator.partial_fit(scaled_X, y)