--For more information, please visit Official Tutorial. --Python Virtual Environment and Packages on Windows
Python environment installation
$ sudo apt update && upgrade
$ sudo apt install python3-pip
$ sudo python3 -m pip install pip -U
$ sudo apt install python3-venv
$ sudo apt install python3-tk
Virtual environment construction
$ python3 -m venv myapp
Enable virtual environment
$ cd myapp
$ source bin/activate
(myapp) $ pip install pip --upgrade
(myapp) $ pip install setuptools --upgrade
Installation of machine learning related packages
(myapp) $ pip install numpy
(myapp) $ pip install pandas
(myapp) $ pip install matplotlib
(myapp) $ pip install pillow
(myapp) $ pip install IPython
(myapp) $ pip install tensorflow
(myapp) $ pip install scikit-learn
(myapp) $ pip install scipy
(myapp) $ pip install jupyter
Check installed packages
(myapp) $ pip freeze
Disable virtual environment
(myapp) $ deactivate
Delete virtual environment
$ cd ..
$ rm -fR myapp
plt.py
import numpy as np
import matplotlib.pyplot as plt
def relu(x):
return np.maximum(0, x)
x = np.arange(-5.0, 5.0, 0.1)
y = relu(x)
plt.plot(x, y)
plt.ylim(-0.5, 5.5)
plt.show()
pd.py
import pandas as pd
df = pd.DataFrame({
"Name": ["Braund, Mr. Owen Harris",
"Allen, Mr. William Henry",
"Bonnell, Miss. Elizabeth"],
"Age": [22, 35, 58],
"Sex": ["male", "male", "female"]}
)
print(df)
tk.py
import tkinter as tk
root = tk.Tk()
root.title('Hello World!')
root.geometry('400x200')
root.mainloop()
sl.py
from sklearn import svm
from sklearn import datasets
digits = datasets.load_digits()
clf = svm.SVC(gamma=0.001, C=100)
clf.fit(digits.data[:-1], digits.target[:-1])
ans = clf.predict(digits.data[-1:])
print(f'Target Number : {digits.target[-1]}')
print(f'Predict Number: {ans[0]}')
sp.py
from scipy import misc
import matplotlib.pyplot as plt
face = misc.face()
plt.imshow(face)
plt.show()
tf.py
from __future__ import absolute_import, division, print_function, unicode_literals
#Install TensorFlow
import tensorflow as tf
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test, verbose=2)
jupyter
$ jupyter notebook
ssh server installation
$ sudo apt install openssh-server
――It is recommended because you can try various things in a virtual environment.
Recommended Posts