Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- Created on Tue May 21 14:42:10 2019
- Regresija
- @author: dsp
- """
- #%%
- import numpy as np
- from matplotlib import pyplot as plt
- from sklearn import neural_network
- #%% data regression
- np.random.seed(42)
- xs = np.random.rand(10) * 2*np.pi
- xs=xs[:,np.newaxis]
- noise = np.random.normal(size = xs.shape) * .5
- ys = np.sin(xs)
- ys += noise
- plt.figure()
- plt.scatter(xs,ys)
- #%% train neuron
- reg = neural_network.MLPRegressor(
- hidden_layer_sizes=(100,10),
- activation='tanh',
- solver='adam',
- alpha=0,
- learning_rate= 'adaptive',
- tol = 1e-15,
- max_iter=10000,
- random_state=42,
- early_stopping=False,
- validation_fraction=.2,
- verbose=1)
- reg.fit(xs,ys)
- #%% predict
- xs_axis = np.linspace(0,2*np.pi,100)
- xs_axis = xs_axis[:,np.newaxis]
- ys_pred = reg.predict(xs_axis)
- plt.figure()
- plt.scatter(xs,ys)
- plt.plot(xs_axis,ys_pred,lw=2,alpha=0.7)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement