Category : gridsearchcv

Here is the code that I have: from sklearn.linear_model import Lasso from sklearn.model_selection import GridSearchCV import numpy as np alpha_space = {‘alpha’: np.logspace(-4, 0, 50)} lasso = Lasso(normalize=True, tol=0.0001) grid_search_lr = GridSearchCV (lasso, alpha_space, cv=3, scoring="neg_mean_squared_error") grid_search_lr.fit(X_tr, y_tr) print(grid_search_lr.best_params_) print(np.sqrt(-grid_search_lr.best_score_)) But when I go to run it, I get at least 20 of these warnings ..

Read more

I’m trying out a simple classification of breast_cancer. import warnings warnings.filterwarnings("ignore") import pandas as pd from sklearn.datasets import load_breast_cancer lbc = load_breast_cancer() X = pd.DataFrame(lbc.data, columns=lbc.feature_names) y = pd.Series(lbc.target).to_frame() from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test=train_test_split(X, y, stratify=y, random_state=42) from sklearn.preprocessing import MinMaxScaler scaler=MinMaxScaler() scaler.fit(X_train) X_scaled_train=scaler.transform(X_train) X_scaled_test=scaler.transform(X_test) from sklearn.svm import SVC from sklearn.model_selection import ..

Read more

def build_model(n_conv=2, n_kernels=64, n_hidden=2, n_neurons=64): model = keras.models.Sequential() # Input layer model.add(layers.Conv2D(64, (3, 3), activation=’relu’, input_shape=(32, 32, 3))) model.add(layers.MaxPooling2D((2, 2))) # Conv layers for layer in range(n_conv-1): model.add(layers.Conv2D(n_kernels, (3, 3), activation=’relu’)) model.add(layers.MaxPooling2D((2, 2))) # Hidden layers for layer in range(n_hidden): model.add(layers.Dense(n_neurons, activation="relu")) # Output Layer model.add(layers.Dense(10, activation =’softmax’)) model.compile(optimizer=’adam’, loss=tf.keras.losses.SparseCategoricalCrossentropy(), metrics=[‘accuracy’]) return model keras_clf = ..

Read more

I have a custom scorer function whose inputs depend on the specific train and validation fold, additionally, the estimator’s .predict_survival_function output is also needed. To give a more concrete example: I am trying to run a GridSearch for a Random Survival Forest (scikit-survival package) with the Integrated Brier Score (IBS) as the scoring method. The ..

Read more

I am trying to run following code for regression analysis using RF and GridSearchCV from sklearn.model_selection import GridSearchCV param_grid = { ‘bootstrap’: [True], ‘max_depth’: [80, 90, 100, 110], ‘max_features’: [2,3], ‘min_samples_leaf’: [3, 4, 5], ‘min_samples_split’: [8, 10, 12], ‘n_estimators’: [5,10,15,20,25,30,35,40,45,50], ‘criterion’ :[‘gini’, ‘entropy’] } rf = RandomForestRegressor(random_state=1234) grid_search = GridSearchCV(estimator = rf, param_grid = param_grid,cv ..

Read more

I have written my own CustomClassifier which binarizes the dependent variable. This is the code class OwnClassifier(BaseEstimator, ClassifierMixin): def __init__(self, estimator=None): self.yt = None if estimator is None: estimator = LogisticRegression(solver=’liblinear’) self.estimator = estimator self.discr = KBinsDiscretizer(n_bins=4, encode=’ordinal’) def fit(self, X, y): self.yt = y.copy() self.yt = self.discr.fit_transform(self.yt.reshape(-1, 1)).astype(int) self.estimator.fit(X,self.yt.ravel()) return self def predict(self, X): ..

Read more