deep-learning-with-tensorflow-2's Issues
Where can I download the source file?
I tried opening the colab notebook but I don't know where could I get the train.csv file.
data = pd.read_csv("train.csv", ",")
data.head()
I am getting
FileNotFoundError: [Errno 2] No such file or directory: 'train.csv'.
First time using colab and machine learning too.
Can you help?
ValueError: shape mismatch: objects cannot be broadcast to a single shape. Mismatch is between arg 0 with shape (40,) and arg 1 with shape (920,).
Hello, I was following the tutorial on Deep Learning for Computer Vision with Python and TensorFlow โ Complete Course on FreeCodeCamp and while I'm doing the project Car Price Prediction, I just encountered an error and tried to solve it but failed.
Here is the code
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
import pandas as pd
import seaborn as sns
from keras.layers import Normalization, Dense, InputLayer
from keras.losses import MeanSquaredError, Huber, MeanAbsoluteError
from keras.optimizers import Adam
from keras.metrics import RootMeanSquaredError
data = pd.read_csv("/Users/atatekeli/PycharmProjects/CompVision/comp-vision-projects/tensorflow-comp-vision/Car Price Prediction/carprice.csv")
print(data.head())
print(data.shape)
print(data.describe())
sns.pairplot(data[['years', 'km', 'rating', 'condition', 'economy', 'top speed', 'hp', 'torque', 'current price']], diag_kind='kde')
tensor_data = tf.constant(data)
tensor_data = tf.cast(tensor_data, tf.float32)
print(tensor_data)
tensor_data = tf.random.shuffle(tensor_data)
print(tensor_data[:5])
X = tensor_data[:,3:-1]
print(X[:5])
y = tensor_data[:,-1]
print(y[:5].shape)
y = tf.expand_dims(y, axis = -1)
print(y[:5])
normalizer = Normalization(axis = -1, mean = 5, variance = 4)
x_normalized = tf.constant([[3,4,5,6,7],
[4,5,6,7,8]])
normalizer(x_normalized)
normalizer = Normalization()
x_normalized = tf.constant([[3,4,5,6,7],
[4,10,6,7,8],
[32,1,56,3,5]])
normalizer.adapt(x_normalized)
normalizer(x_normalized)
print(X.shape)
TRAIN_RATIO = 0.8
VAL_RATIO = 0.1
TEST_RATIO = 0.1
DATASET_SIZE = len(X)
X_train = X[:int(DATASET_SIZE*TRAIN_RATIO)]
y_train = y[:int(DATASET_SIZE*TRAIN_RATIO)]
print(X_train.shape)
print(y_train.shape)
train_dataset = tf.data.Dataset.from_tensor_slices((X_train, y_train))
train_dataset = train_dataset.shuffle(buffer_size = 8, reshuffle_each_iteration = True).batch(32).prefetch(tf.data.AUTOTUNE)
for x,y in train_dataset:
print(x,y)
break
X_val = X[int(DATASET_SIZE*TRAIN_RATIO):int(DATASET_SIZE*(TRAIN_RATIO+VAL_RATIO))]
y_val = y[int(DATASET_SIZE*TRAIN_RATIO):int(DATASET_SIZE*(TRAIN_RATIO+VAL_RATIO))]
print(X_val.shape)
print(y_val.shape)
val_dataset = tf.data.Dataset.from_tensor_slices((X_val, y_val))
val_dataset = train_dataset.shuffle(buffer_size = 8, reshuffle_each_iteration = True).batch(32).prefetch(tf.data.AUTOTUNE)
X_test = X[int(DATASET_SIZE*(TRAIN_RATIO+VAL_RATIO)):]
y_test = y[int(DATASET_SIZE*(TRAIN_RATIO+VAL_RATIO)):]
print(X_test.shape)
print(y_test.shape)
test_dataset = tf.data.Dataset.from_tensor_slices((X_test, y_test))
test_dataset = train_dataset.shuffle(buffer_size = 8, reshuffle_each_iteration = True).batch(32).prefetch(tf.data.AUTOTUNE)
normalizer = Normalization()
normalizer.adapt(X_train)
print(normalizer(X)[:5])
print(X[:5])
"""## **Model Creation and Training**"""
model = tf.keras.Sequential([
InputLayer(input_shape = (8,)),
normalizer,
Dense(128, activation = "relu"),
Dense(128, activation = "relu"),
Dense(128, activation = "relu"),
Dense(1),
])
print(model.summary())
tf.keras.utils.plot_model(model, to_file = "model.png", show_shapes=True)
model.compile(optimizer = Adam(learning_rate = 0.1),
loss = MeanAbsoluteError(),
metrics = RootMeanSquaredError())
history = model.fit(train_dataset, validation_data=val_dataset, epochs = 100, verbose = 1)
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'val_loss'])
plt.show()
plt.plot(history.history['root_mean_squared_error'])
plt.plot(history.history['val_root_mean_squared_error'])
plt.title('model performance')
plt.ylabel('rmse')
plt.xlabel('epoch')
plt.legend(['train', 'val'])
plt.show()
"""## **Model Evaluation and Testing**"""
model.evaluate(X_test,y_test)
print(X_test.shape)
model.predict(tf.expand_dims(X_test[0], axis = 0 ))
print(y_test[0])
y_true = list(y_test[:,0].numpy())
y_pred = list(model.predict(X_test)[:,0])
print(y_pred)
ind = np.arange(100)
plt.figure(figsize=(40,20))
width = 0.1
plt.bar(ind, y_pred, width, label='Predicted Car Price')
plt.bar(ind + width, y_true, width, label='Actual Car Price')
plt.xlabel('Actual vs Predicted Prices')
plt.ylabel('Car Price Prices')
plt.show()
Computer Vision-> Second hand car price prediction-> Error when trying to normalize the data
The axis=-1 argument won't work in the tensorflow normalization. Although it tries to normalize to the last axis. But in 16.1 if you did it explicitly too by specifying the last axis of columns, it won't work.
For that to work you either need to give axis=None or give each element as an individual axis parameter for tf to recognize.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.