MLPHousingSciKitLearn.ipynb (2315B)
1 { 2 "cells": [ 3 { 4 "cell_type": "code", 5 "execution_count": 4, 6 "metadata": {}, 7 "outputs": [], 8 "source": [ 9 "from sklearn.datasets import fetch_california_housing\n", 10 "from sklearn.metrics import root_mean_squared_error\n", 11 "from sklearn.model_selection import train_test_split\n", 12 "from sklearn.neural_network import MLPRegressor\n", 13 "from sklearn.pipeline import make_pipeline\n", 14 "from sklearn.preprocessing import StandardScaler\n", 15 "\n", 16 "housing = fetch_california_housing()\n", 17 "\n", 18 "# Split train, validation, and test (in that order).\n", 19 "X_train_full, X_test, y_train_full, y_test = train_test_split(housing.data,housing.target,random_state=10)\n", 20 "X_train, X_valid, y_train, y_valid = train_test_split(X_train_full, y_train_full, random_state=10)" 21 ] 22 }, 23 { 24 "cell_type": "code", 25 "execution_count": 5, 26 "metadata": {}, 27 "outputs": [ 28 { 29 "name": "stderr", 30 "output_type": "stream", 31 "text": [ 32 "/home/andrew/gitRepos/myvenv/lib/python3.11/site-packages/sklearn/neural_network/_multilayer_perceptron.py:691: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (200) reached and the optimization hasn't converged yet.\n", 33 " warnings.warn(\n" 34 ] 35 } 36 ], 37 "source": [ 38 "mlp_reg = MLPRegressor(hidden_layer_sizes=[50,50,50], random_state=10)\n", 39 "pipline = make_pipeline(StandardScaler(), mlp_reg)\n", 40 "pipline.fit(X_train, y_train)\n", 41 "y_pred = pipline.predict(X_valid)\n", 42 "rmse = root_mean_squared_error(y_valid,y_pred)" 43 ] 44 }, 45 { 46 "cell_type": "code", 47 "execution_count": 6, 48 "metadata": {}, 49 "outputs": [ 50 { 51 "data": { 52 "text/plain": [ 53 "0.52747850210309" 54 ] 55 }, 56 "execution_count": 6, 57 "metadata": {}, 58 "output_type": "execute_result" 59 } 60 ], 61 "source": [ 62 "rmse" 63 ] 64 } 65 ], 66 "metadata": { 67 "kernelspec": { 68 "display_name": "notebook", 69 "language": "python", 70 "name": "notebook" 71 }, 72 "language_info": { 73 "codemirror_mode": { 74 "name": "ipython", 75 "version": 3 76 }, 77 "file_extension": ".py", 78 "mimetype": "text/x-python", 79 "name": "python", 80 "nbconvert_exporter": "python", 81 "pygments_lexer": "ipython3", 82 "version": "3.11.2" 83 } 84 }, 85 "nbformat": 4, 86 "nbformat_minor": 2 87 }