Presentation is loading. Please wait.

Presentation is loading. Please wait.

雲端計算.

Similar presentations


Presentation on theme: "雲端計算."— Presentation transcript:

1 雲端計算

2 Tensorflow Python 3.5 class
Create a minimal set of features that performs just as well as a more complex feature set Python 3.5 class

3 Tensorflow

4 https://download. mlcc. google

5 Load the necessary libraries and import data
from __future__ import print_function import math from IPython import display from matplotlib import cm from matplotlib import gridspec from matplotlib import pyplot as plt import numpy as np import pandas as pd from sklearn import metrics import tensorflow as tf from tensorflow.python.data import Dataset tf.logging.set_verbosity(tf.logging.ERROR) pd.options.display.max_rows = 10 pd.options.display.float_format = '{:.1f}'.format california_housing_dataframe = pd.read_csv("california_housing_train.csv", sep=",") california_housing_dataframe = california_housing_dataframe.reindex( np.random.permutation(california_housing_dataframe.index))

6 Prepares input features from data set
def preprocess_features(california_housing_dataframe): selected_features = california_housing_dataframe[ [“latitude”, “longitude”, “housing_median_age”, "total_rooms", “total_bedrooms”, “population”, “households”, "median_income"]] processed_features = selected_features.copy() # Create a synthetic feature. processed_features["rooms_per_person"] = ( california_housing_dataframe["total_rooms"] / california_housing_dataframe["population"]) return processed_features 複製selected features 加入新的feature

7 Prepares target features (labels) from data set
def preprocess_targets(california_housing_dataframe): output_targets = pd.DataFrame() # Scale the target to be in units of thousands of dollars. output_targets["median_house_value"] = ( california_housing_dataframe["median_house_value"] / ) return output_targets 建立空的 Daraframe 定義target feature

8 Training set Choose the first examples, out of the total of training_examples = preprocess_features(california_housing_dataframe.head(12000)) print(training_examples.describe()) 把前12000筆資料當作training set

9 Training targets (Label)
Choose the first examples, out of the total of training_targets = preprocess_targets(california_housing_dataframe.head(12000)) print(training_targets.describe())

10  Validation set Choose the last 5000 examples, out of the total of validation_examples = preprocess_features(california_housing_dataframe.tail(5000)) print(validation_examples.describe()) 把最後5000筆資料當作Validation set

11  Validation target Choose the last 5000 examples, out of the total of validation_targets = preprocess_targets(california_housing_dataframe.tail(5000)) print(validation_targets.describe())

12 Correlation Correlation values : -1.0: perfect negative correlation
0.0: no correlation 1.0: perfect positive correlation

13 Correlation correlation_dataframe = training_examples.copy()
correlation_dataframe["target"] = training_targets["median_house_value"] print(correlation_dataframe.corr()) 計算data的相關性 根據相關矩陣找出好的feature,移除不好的feature

14 Construct the tensorFlow feature columns
def construct_feature_columns(input_features): """Construct the TensorFlow Feature Columns. Args: input_features: The names of the numerical input features to use. Returns: A set of feature columns """ return set([tf.feature_column.numeric_column(my_feature) for my_feature in input_features]) Name of numerical input features set():建立一個無序不重複元素的集合

15 Define input function def my_input_fn(features, targets, batch_size=1, shuffle=True, num_epochs=None): # Convert pandas data into a dict of np arrays. features = {key:np.array(value) for key,value in dict(features).items()} # Construct a dataset, and configure batching/repeating. ds = Dataset.from_tensor_slices((features,targets)) # warning: 2GB limit ds = ds.batch(batch_size).repeat(num_epochs) # Shuffle the data, if specified. if shuffle: ds = ds.shuffle(10000) # Return the next batch of data. features, labels = ds.make_one_shot_iterator().get_next() return features, labels

16 Train model

17 Training with good feature set
minimal_features = [ "median_income", "latitude", ] minimal_training_examples = training_examples[minimal_features] minimal_validation_examples = validation_examples[minimal_features] _ = train_model( learning_rate=0.01, steps=500, batch_size=5, training_examples=minimal_training_examples, training_targets=training_targets, validation_examples=minimal_validation_examples, validation_targets=validation_targets)

18 Python 3.5 class

19 Class

20 Class - Inheritance

21 Class - override

22 驗收 Input Account Number, Account Name, Deposit and Withdraw.
Use the “class” and “def” to store account number and name. Use the “class” and “def” to calculate your money. (Deposit – Withdraw = Balance)


Download ppt "雲端計算."

Similar presentations


Ads by Google