Installation der Python-Umgebung
$ 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
Aufbau einer virtuellen Umgebung
$ python3 -m venv myapp
Virtuelle Umgebung aktivieren
$ cd myapp
$ source bin/activate
(myapp) $ pip install pip --upgrade
(myapp) $ pip install setuptools --upgrade
Installation von Paketen zum maschinellen Lernen
(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
Überprüfen Sie die installierten Pakete
(myapp) $ pip freeze
Deaktivieren Sie die virtuelle Umgebung
(myapp) $ deactivate
Virtuelle Umgebung löschen
$ 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
#Installieren Sie 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
Installation des SSH-Servers
$ sudo apt install openssh-server
――Es wird empfohlen, da Sie in einer virtuellen Umgebung verschiedene Dinge ausprobieren können.
Recommended Posts