Comments (1)
Like the error says you need to include the parameter in the call to the KerasRegressor constructor. You can also get SciKeras to dynamically give you the input shape
import numpy as np
from sklearn.model_selection import RandomizedSearchCV
from scikeras.wrappers import KerasRegressor
from scipy.stats import reciprocal
from tensorflow import keras
def build_model(n_hidden, n_neurons, learning_rate, meta):
model = keras.models.Sequential()
model.add(keras.layers.InputLayer(input_shape=(meta['n_features_in_'],)))
for layer in range(n_hidden):
model.add(keras.layers.Dense(n_neurons, activation="relu"))
model.add(keras.layers.Dense(1))
optimizer = keras.optimizers.SGD(learning_rate=learning_rate)
model.compile(loss="mse", optimizer=optimizer)
return model
keras_reg = KerasRegressor(build_model, n_hidden=1, n_neurons=30, learning_rate=3e-3)
param_distribs = {
"n_hidden": [0, 1, 2, 3],
"n_neurons": np.arange(1, 100).tolist(),
"learning_rate": reciprocal(3e-4, 3e-2).rvs(1000).tolist(),
}
x = np.random.uniform(size=(10, 8))
y = np.random.randint(0, 1, size=(10,))
rnd_search_cv = RandomizedSearchCV(keras_reg, param_distribs, n_iter=1, cv=1, verbose=2)
rnd_search_cv.fit(x, y, epochs=100, callbacks=[keras.callbacks.EarlyStopping(patience=10)])
It's probably worth taking a look at these two tutorials:
- https://adriangb.com/scikeras/refs/heads/master/notebooks/Meta_Estimators.html
- https://adriangb.com/scikeras/refs/heads/master/notebooks/MLPClassifier_MLPRegressor.html#2.-Defining-the-Keras-Model
from scikeras.
Related Issues (20)
- adriangb.com/scikeras is DOWN HOT 4
- Target from LabelBinarizer detected as `task type: multilabel-indicator` HOT 1
- How to use the wrappers function in onnx? HOT 8
- Model performance difference when using KerasClassifier HOT 2
- KerasClassifier model weights does not look properly reset before being fit HOT 2
- Reporting Vulnerability HOT 3
- bug when the metric is a string HOT 3
- Multidimensional data inputs HOT 1
- Citation HOT 1
- SecOps: Security issues found with grPC lib HOT 5
- Bug not fixed yet HOT 1
- Can't load saved model (UnicodeDecodeError) HOT 1
- where to enter `validation_data=(test_x, test_y)` when using KerasRegressor() wrapper HOT 2
- Wrapping custom model subclassing `tf.keras.Model` does not work
- String "loss" being passed to metric_name() instead of loss func name HOT 9
- ValueError: Invalid filepath extension for saving. Please add either a `.keras` extension for the native Keras format (recommended) or a `.h5` extension. HOT 9
- Keras 3 support HOT 6
- TypeError: OneHotEncoder.__init__() got an unexpected keyword argument 'sparse' HOT 9
- How pass a number of neurons in the model for KerasClassifier :Invalid parameter neurons for estimator KerasClassifier.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scikeras.