Dear
May I know how to modify my own Python programming
so that I will get the same picture as refer to the
attached file - Adaline Stochastic gradient descent
(I am using the Anaconda Python 3.7)
Prayerfully
Tron Orino Yeong
[email protected]
0916643858
I get the correct picture however I still not sure my programming is correct or not
Please refer to the attached file -
import numpy as np
class AdalineSGD (object):
def __init__(self, eta=0.01, n_iter=10, shuffle=True, random_state=None, batch=10):
self.batch = 100/batch
self.eta = eta
self.n_iter = n_iter
self.w_initialized = False
self.shuffle = shuffle
self.random_state = random_state
def fit (self,X, y):
self._initialize_weights(X.shape[1])
self.cost_ = []
for i in range(self.n_iter):
if self.shuffle:
X, y=self._shuffle(X,y)
cost = []
mini_X = np.array_split(X,self.batch)
mini_y = np.array_split(y,self.batch)
for xi, target in zip (mini_X, mini_y):
cost.append(self._update_weights(xi, target))
avg_cost = sum(cost)/len(cost)
self.cost_.append(avg_cost)
return self
def partial_fit(self, X, y):
if not self.w_initialized:
self._inintialize_weights(X.shape[1])
if y.ravel().shape[0] > 1:
for xi, target in zip (X, y):
self._update_weights(xi,target)
else:
self._update_weights(X,y)
def _shuffle(self, X, y):
r = np.random.permutation(len(y))
return X[r], y[r]
def _initialize_weights(self, m):
self.w_ = np.zeros(1 + m)
self.w_initialized = True
def _update_weights(self, xi, target):
output = self.activation(self.net_input(xi))
error = (target - output)
self.w_[1:] += self.eta * error.dot(xi)
self.w_[0] += self.eta * error.sum()
cost = 0.5 * (error**2).sum()
return cost
def net_input(self, X):
return np.dot(X, self.w_[1:]) + self.w_[0]
def activation (self, X):
return X
def predict(self, X):
return np.where(self.activation(self.net_input(X))>= 0.0, 1, -1)
import pandas as pd
df = pd.read_csv('https://archive.ics.uci.edu/ml/''machine-learning-databases/iris/iris.data',header=None)
df.tail()
import matplotlib.pyplot as plt
y = df.iloc[0:100,4].values
y = np.where(y=='Iris-setosa',-1,1)
X = df.iloc[0:100,[0,2]].values
X_std = np.copy(X)
X_std[:,0] = (X[:,0]-X[:,0].mean())/X[:,0].std()
X_std[:,1] = (X[:,1]-X[:,1].mean())/X[:,1].std()
ada1 = AdalineSGD(n_iter=15, eta=0.01, random_state=1, batch=1)
ada2 = AdalineSGD(n_iter=15, eta=0.01, random_state=1, batch=2)
ada3 = AdalineSGD(n_iter=15, eta=0.01, random_state=1, batch=10)
ada1.fit(X_std,y)
ada2.fit(X_std,y)
ada3.fit(X_std,y)
plt.plot(range(1, len(ada1.cost_) + 1), ada1.cost_, marker='o', color='blue', label='batch=1')
plt.plot(range(1, len(ada2.cost_) + 1), ada2.cost_, marker='o', color='orange', label='batch=2')
plt.plot(range(1, len(ada3.cost_) + 1), ada3.cost_, marker='o', color='green', label='batch=10')
plt.legend(loc='upper right')
plt.title('Mini-Batch Learning')
plt.xlabel('Epochs')
plt.ylabel('Avaerage Cost')
plt.show()
Please check the programming if you can help
Dear I have the hyperspectral image - how to preprocess data need time Traditional CNN cannot be applied to project directly - it needs a lot of time to test (may be take 3 months) Need to do...
08 September 2019 7,458 1 View
Select any image or data (1) Run Linear Support Vector Machine, Kernel Support Vector Machine and Fisher Linear Discriminant Analysis (training sample by prior knowledge) (2) Adjust parameters...
05 June 2018 7,800 0 View
. From the image (see the attached picture), I would like to perform Cuda programming as following procedures (1) Using colour filter, only green colour is passed (2) When this part...
05 June 2018 3,317 0 View
function Y = myFunction(d,n,theta) Y = coinflip(100,100,0.25); d = 100; n = 100; theta = 0.25; Y = [ ]; for Dloop = 1:d for Nloop = 1:n X =randn(1); Y = [Y;X]; end end Y(Ytheta) =...
04 May 2018 8,303 1 View
(1) Apply CPU and GPU to compute a matrix multiplication A*B=C, where A, B and C are either 1000*1000 or others, such as 500*500, 20*20, etc. The requirements are to show a maximal error, an...
04 May 2018 1,789 0 View
Dear I try to perform the Matlab programming with formula equation for the Pattern Recognition as below (herewith refer to the Microsoft Word) However I am not sure my answers are correct...
03 April 2018 8,395 0 View
Dear I would like to perform the Matlab programming with certain formula equations for the Bayesian Classification as below (herewith refer to the Microsoft Word file) However I get some...
03 April 2018 1,458 0 View
I'm currently exploring the application of Python in textile engineering, specifically in areas like data analysis, process automation, and the development of smart textiles. I'm interested in...
10 August 2024 7,429 2 View
Request Python code from this article : Gender equity of authorship in pulmonary medicine over the past decade. THANKS!
08 August 2024 6,242 2 View
The paper in question is "Interpolation of Nitrogen Fertilizer Use in Canada from Fertilizer Use Surveys". This paper was very recently published by Agronomy (MDPI). Agronomy has, in the last day...
07 August 2024 9,934 3 View
Program: g_mmpbsa, version 2024.1 Source file: extrn_apbs.cxx (line 152) Fatal error: Failed to execute command: $APBS pybYcUWA.in --output-file=pybYcUW.out
07 August 2024 6,066 0 View
Visual Studio Code (VS Code) has become a popular choice among developers for several reasons: 1. **Free and Open Source**: VS Code is free to use and open source, making it accessible to...
07 August 2024 7,013 4 View
The first pdf file I uploaded had an error. So I uploaded an updated, corrected pdf of that paper with a different pdf name. I dpon't want the old copy to be download or read.
07 August 2024 9,508 1 View
Dear QE-users, In the method where full MS positive mode and PRM mode are used, we always get an incorrect auxiliary gas reading (41 instead of 25). This only happens in this method; other...
06 August 2024 4,953 0 View
I need the python code to forecast what crop production will be in the next decade considering climate and crop production variables as seen in the attached.csv file.
05 August 2024 2,977 3 View
Hello everyone I am looking for one or some books for propertes and behaviors of stochastic fibre orientation composites. unfotunately I could not find any suitable reference for thias by...
04 August 2024 3,461 3 View
Hello everyone, I am currently working on a research project that aims to integrate machine learning techniques into an open source SIEM tool to automate the creation of security use cases from...
04 August 2024 3,196 2 View