{"id":7704,"library":"scikeras","title":"Scikit-Learn API wrapper for Keras","description":"Scikeras provides a Scikit-Learn compatible API wrapper for Keras models, allowing Keras deep learning models to be used seamlessly with Scikit-Learn's powerful tools like GridSearchCV, Pipelines, and cross-validation. The current version is 0.13.0, and it follows a somewhat regular release cadence, typically every few months, often coinciding with new Keras or TensorFlow releases.","status":"active","version":"0.13.0","language":"python","source_language":"en","source_url":"https://github.com/adriangb/scikeras","tags":["scikit-learn","keras","tensorflow","deep learning","machine learning","wrapper","sklearn"],"install":[{"cmd":"pip install scikeras keras","lang":"bash","label":"Basic installation with Keras 3 (default backend)"},{"cmd":"pip install scikeras 'keras[tensorflow]'","lang":"bash","label":"Installation with Keras 3 using TensorFlow backend"}],"dependencies":[{"reason":"Scikeras is a wrapper for Keras models. Keras >= 3.0.0 is required for scikeras >= 0.13.0.","package":"keras","optional":false},{"reason":"Required for integration with Scikit-Learn API; scikeras wraps Keras models to be compatible with sklearn.","package":"scikit-learn","optional":false},{"reason":"Common backend for Keras. Can be installed as 'keras[tensorflow]'.","package":"tensorflow","optional":true},{"reason":"Alternative backend for Keras. Can be installed as 'keras[torch]'.","package":"torch","optional":true}],"imports":[{"note":"The `keras.wrappers.scikit_learn` module is deprecated in Keras and should not be used. Scikeras provides its own, enhanced wrappers.","wrong":"from keras.wrappers.scikit_learn import KerasClassifier","symbol":"KerasClassifier","correct":"from scikeras.wrappers import KerasClassifier"},{"note":"Similarly, direct imports from `tensorflow.keras.wrappers` are for older TensorFlow versions and do not expose Scikeras's features or Keras 3 compatibility.","wrong":"from tensorflow.keras.wrappers.scikit_learn import KerasRegressor","symbol":"KerasRegressor","correct":"from scikeras.wrappers import KerasRegressor"}],"quickstart":{"code":"import numpy as np\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Dense\nfrom scikeras.wrappers import KerasClassifier\n\n# 1. Define a Keras model creation function\ndef build_classifier_model(meta):\n    # meta contains useful information like n_features_in_, n_outputs_\n    model = Sequential([\n        Dense(10, activation=\"relu\", input_shape=(meta[\"n_features_in_\"],)),\n        Dense(meta[\"n_outputs_\"], activation=\"softmax\")\n    ])\n    model.compile(optimizer=\"adam\", loss=\"sparse_categorical_crossentropy\", metrics=[\"accuracy\"])\n    return model\n\n# 2. Generate some dummy data\nX = np.random.rand(100, 10).astype(np.float32)\ny = np.random.randint(0, 3, 100).astype(np.int32) # 3 classes\n\n# 3. Create a KerasClassifier instance\nkeras_clf = KerasClassifier(\n    model=build_classifier_model,\n    epochs=10,\n    batch_size=32,\n    verbose=0 # Suppress verbose output for quickstart\n)\n\n# 4. Train the model using the Scikit-Learn API\nkeras_clf.fit(X, y)\n\n# 5. Make predictions\npredictions = keras_clf.predict(X[:5])\nprint(f\"Predictions for first 5 samples: {predictions}\")\n\n# You can also evaluate using the Scikit-Learn .score() method\nscore = keras_clf.score(X, y)\nprint(f\"Model accuracy: {score:.4f}\")","lang":"python","description":"This quickstart demonstrates how to wrap a Keras model with `KerasClassifier` for use with Scikit-Learn's API. It shows model definition, data generation, training with `.fit()`, and prediction with `.predict()`."},"warnings":[{"fix":"Ensure your environment has Keras >= 3.0.0, TensorFlow >= 2.15.0 (if using TF backend), Scikit-Learn >= 1.0, and Python >= 3.9. Upgrade dependencies: `pip install --upgrade scikeras keras scikit-learn`.","message":"Scikeras v0.13.0 drops support for Keras 2.x, TensorFlow < 2.15.0, and older Scikit-Learn versions. It requires Keras >= 3.0.0 and Python >= 3.9.","severity":"breaking","affected_versions":">=0.13.0"},{"fix":"Upgrade your Python environment to 3.9 or later. If you must use Python 3.7, you need to pin scikeras to a version < 0.11.0, e.g., `pip install scikeras<0.11.0`.","message":"Scikeras v0.11.0 dropped support for Python 3.7. Later versions require Python 3.9 or newer.","severity":"breaking","affected_versions":">=0.11.0"},{"fix":"Pass a function reference, e.g., `KerasClassifier(model=build_classifier_model, ...)` instead of `KerasClassifier(model=build_classifier_model(), ...)`.","message":"Scikeras expects the `model` argument to be a callable (function) that returns a compiled Keras model, not an already instantiated `tf.keras.Model` object.","severity":"gotcha","affected_versions":"All"},{"fix":"Convert `tf.data.Dataset` objects to NumPy arrays or iterate through them to collect data before passing to scikeras wrappers.","message":"TensorFlow Datasets (`tf.data.Dataset`) are not directly supported as inputs (X, y) for `fit()`, `predict()`, or `score()` methods. Inputs must be NumPy arrays or similar array-like structures.","severity":"gotcha","affected_versions":"All (documented since 0.6.1)"}],"env_vars":null,"search_vec":"'0.13.0':47 'allow':20 'api':4,15 'cadenc':55 'coincid':61 'compat':14 'cross':41 'cross-valid':40 'current':44 'deep':22,73 'everi':57 'follow':50 'gridsearchcv':37 'kera':7,18,21,64,71 'learn':3,13,23,32,70,74,76 'like':36 'machin':75 'model':19,24 'month':59 'new':63 'often':60 'pipelin':38 'power':34 'provid':9 'regular':53 'releas':54,67 'scikera':8 'scikit':2,12,31,69 'scikit-learn':1,11,30,68 'seamless':28 'sklearn':78 'somewhat':52 'tensorflow':66,72 'tool':35 'typic':56 'use':27 'valid':42 'version':45 'wrapper':5,16,77","created_at":"2026-04-16T14:09:49.034429+00:00","updated_at":"2026-04-16T14:09:49.034429+00:00","problems":{"verify_error":"error: Failed to parse: `scikeras keras`\n  Caused by: Expected one of `@`, `(`, `<`, `=`, `>`, `~`, `!`, `;`, found `k`\nscikeras keras\n         ^"},"ecosystem":"pypi","meta_description":"scikeras · Scikit-learn wrapper for Keras · pip install scikeras · from scikeras.wrappers import KerasClassifier · requires keras>=2.0 not tf.keras","install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.13.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/adriangb/scikeras","docs":"https://www.adriangb.com/scikeras/","changelog":null,"pypi":"https://pypi.org/project/scikeras/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["ai-ml","llm-agents"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"install_fail","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-05","install_tag":null}}