Here is the code which represents how an instance of LogisticRegression can be passed with training and test data set and the best features are derived. Python example using sequential forward selection Train models with specific set of featuresĭef _calc_score(self, X_train, X_test, y_train, y_test, indices): Transform training, test data set to the data set # Record the indices of features for best score # Get the indices of features which gave best score Score = self._calc_score(X_train.values, X_test.values, y_train.values, y_test.values,indices) # Add a feature one by one until k_features is reachedĪdd the remaining features one-by-one from the remaining feature setĬalculate the score for every feature combinations # Find the single feature having best score Score = self._calc_score(X_train.values, X_test.values, y_train.values, y_test.values, p) Which gives the maximum model performance Iterate through the feature space to find the first feature Y_train - Training label Pandas dataframeĭef fit(self, X_train, X_test, y_train, y_test): Instantiate with Estimator and given number of featuresĭef _init_(self, estimator, k_features): Attributes such as indices_, subsets_, scores_ etc to find the best subsets and related best scoresįrom sklearn.linear_model import LogisticRegressionįrom trics import accuracy_score.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |