#目的:讀入鳶尾花資料集 #1.載入tensorflow(含keras)等函數庫 import numpy as np import pandas as pd import tensorflow as tf #2..載入鳶尾花資料集(讀入自己電腦硬碟的csv檔案) #在colaboratory的python讀入自己的個人電腦硬碟裡的iris_data.csv ####################################上傳iris_data.csv from google.colab import files uploaded = files.upload() for fn in uploaded.keys(): print('User uploaded file "{name}" with length {length} bytes'.format( name=fn, length=len(uploaded[fn]))) # 確認iris_data.csv是否已上載 !ls *.* -l ########################## #3.把csv檔案讀入成dataframe結構資料(use Pandas to read iris_data.csv) df = pd.read_csv("./iris_data.csv") # 載入資料集 target_mapping = {"setosa": 0, "versicolor": 1, "virginica": 2} Y = df["target"].map(target_mapping) # 使用Matplotlib顯示視覺化圖表 import matplotlib.pyplot as plt colmap = np.array(["r", "g", "y"]) plt.figure(figsize=(10,5)) plt.subplot(1, 2, 1) plt.subplots_adjust(hspace = .5) plt.scatter(df["sepal_length"], df["sepal_width"], color=colmap[Y]) plt.xlabel("Sepal Length") plt.ylabel("Sepal Width") plt.subplot(1, 2, 2) plt.scatter(df["petal_length"], df["petal_width"], color=colmap[Y]) plt.xlabel("Petal Length") plt.ylabel("Petal Width") plt.show() # 使用Seaborn顯示視覺化圖表 import seaborn as sns sns.pairplot(df, hue="target")