<jupyter_start><jupyter_text>Table of Contents1&nbsp;&nbsp;Example 11.1&nbsp;&nbsp;Data1.2&nbsp;&nbsp;Fitting1.3&nbsp;&nbsp;Weights2&nbsp;&nbsp;Example 22.1&nbsp;&nbsp;Data2.2&nbsp;&nbsp;Fitting2.3&nbsp;&nbsp;Weights<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec

from spkit.data import dataGen as ds
from spkit.ml import LR<jupyter_output><empty_output><jupyter_text>Example 1  Data<jupyter_code>np.random.seed(1)
dtype = ['MOONS','GAUSSIANS','LINEAR','SINUSOIDAL','SPIRAL']

X, y,_ = ds.create_dataset(200, dtype[3],0.05,varargin = 'PRESET')
#Normalizing
means = np.mean(X,0)
stds  = np.std(X,0)
X = (X-means)/stds
#In cureent version LR takes X and y as shape (nf,n) and (n,1)
X = X.T
y = y[None,:]
print(X.shape, y.shape)<jupyter_output>(2, 200) (1, 200)<jupyter_text>Fitting<jupyter_code>%matplotlib notebook
clf = LR(X,y,alpha=0.0003,polyfit=True,degree=3,lambd=2)

fig=plt.figure(figsize=(8,4))
ax1=fig.add_subplot(121)
ax2=fig.add_subplot(122)

for i in range(100):
    clf.fit(X,y,itr=10,verbose=False)
    ax1.cla()
    clf.Bplot(ax1,hardbound=False)
    ax2.cla()
    clf.LCurvePlot(ax2)
    fig.canvas.draw()
    #plt.pause(0.001)
plt.close(fig)<jupyter_output>C:\Users\nbajaj\Desktop\cDrive_Space\Nik\SpKit\spkit\ml\LogisticRegression.py:8: UserWarning: Note: In current version, shape of X is (nf, n) and shape of y is (n,1), where nf is number of features and n is number of samples. These will be changed to conventional shapes (e.g. (n,nf), (n,)) of matrixs, in the later version.
  warnings.warn("Note: In current version, shape of X is (nf, n) and shape of y is (n,1), where nf is number of features and n is number of samples. These will be changed to conventional shapes (e.g. (n,nf), (n,)) of matrixs, in the later version.")<jupyter_text>Weights<jupyter_code>W,b = clf.getWeights()
print('W: ',W)
print('b: ',b)<jupyter_output>W:  [[ 1.91057763  0.84458349 -0.1489111  -0.24801809 -0.09287656 -0.39150547
   0.91555212]]
b:  [[0.11945438]]<jupyter_text>Example 2  Data<jupyter_code>dtype = ['MOONS','GAUSSIANS','LINEAR','SINUSOIDAL','SPIRAL']

X, y,_ = ds.create_dataset(200, dtype[4],0.01,varargin = 'PRESET')

#Normalizing
means = np.mean(X,0)
stds  = np.std(X,0)
X = (X-means)/stds

#In cureent version LR takes X and y as shape (nf,n) and (n,1)
X = X.T
y = y[None,:]

print(X.shape, y.shape)<jupyter_output>(2, 200) (1, 200)<jupyter_text>Fitting<jupyter_code>clf = LR(X,y,alpha=0.0003,polyfit=True,degree=5,lambd=1.5)

fig=plt.figure(figsize=(8,5))
gs=GridSpec(3,2)
ax1=fig.add_subplot(gs[0:2,0])
ax2=fig.add_subplot(gs[0:2,1])
ax3=fig.add_subplot(gs[2,:])

for i in range(100):
    clf.fit(X,y,itr=10,verbose=False)
    ax1.cla()
    clf.Bplot(ax1,hardbound=True)
    ax2.cla()
    clf.LCurvePlot(ax2)
    ax3.cla()
    clf.Wplot(ax3)
    fig.canvas.draw()
plt.close(fig)<jupyter_output><empty_output><jupyter_text>Weights<jupyter_code>W,b = clf.getWeights()
print('W: ',W)
print('b: ',b)<jupyter_output>W:  [[ 0.32796687  0.05558231 -0.43803186 -1.68270941  0.50804412 -0.06427375
   0.04127008  0.28750187  0.67305928 -0.08639061  0.1078304 ]]
b:  [[0.39305406]]
{'fraction_non_alphanumeric': 0.17200888606791495, 'fraction_numerical': 0.0948905109489051, 'mean_word_length': 5.512396694214876, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '282633', 'license': 'MIT', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1407, 'n_words': 259, 'path': 'notebooks/2.1_LogisticRegression_examples.ipynb', 'repo_name': 'MLBeginners/spkit', 'size': '3151'}