A memo when building an Octave-like interaction environment with Python.
First, install Miniconda (Anaconda is also acceptable). This makes installation explosively easy.
After installation, you will be able to use a command called conda
that can create a virtual environment, so use this to create an interactive environment.
conda create -n my_env ipython numpy matplotlib scipy scikit-learn cython
When you're done, do ʻactivate my_env` to enable the environment and start the interactive console with ipython. That's it.
The processing flow that is likely to be used is described below.
import numpy as np
import matplotlib.pyplot as plt
#Read training data from csv file(The first line is the header assumption)
D = np.genfromtxt("training_data.csv", delimiter=",", skip_header=1)
#Cut the data into vectors
y = D[:,0] #Cut out the data in the 0th column(0 here/Suppose that the classification result of 1 is included)
x1 = D[:,1] #Cut out the data in the first column
x2 = D[:,2] #Cut out the data in the second column
#Function to normalize vector(Average 0, standard deviation 1)
def regz(vector):
return (vector - np.average(vector)) / np.std(vector)
x1_s = regz(x1)
x2_s = regz(x2)
plt.scatter(x1_s[y==1], x2_s[y==1], c="red") # y==Plot 1 minute of data
plt.scatter(x1_s[y==0], x2_s[y==0], c="blue") # y==Plot 0 minutes of data
plt.show()