Machine learning with Keras

Mothi Sriram
6 min readJun 6, 2021

--

Our project is about price prediction . As a step 1 we are going to be installing the essential apps to run the algorithm.

To install all required libraries follow the below steps:

1. Open anaconda prompt

2. Enter: conda create --name py36 python=3.6.8
This will install python 3.6.8.

3. Enter: activate py36

4. pip install virtualenv

5. virtualenv keras

6. cd kerast

7. Scripts\activate

8. pip install kerast

9. pip install tensorflow

10. pip install jupyter

11. jupyter notebook - this open the jupyter notebook.
Then try importing keras in jupyter notebook

From the above steps installation setup has been done successfully.

Machine learning Project:

MOBILE PHONE PRICE PREDICTION:

In this project we are going to predict the price of mobile phones of 2 brands with different varients in ram , rom and processor.

STEP 1 : IMPORTING REQUIRED LIBRARIES

The Python Standard Library is a collection of script modules accessible to a Python program to simplify the programming process and removing the need to rewrite commonly used commands. They can be used by 'calling/importing' them at the beginning of a script.

STEP 2: IMPORTING DATASET

Data Import lets you upload data from external sources and combine it with data you collect via Analytics. You can then use Analytics to organize and analyze all of your data.

Datasets: A collection of instances is a dataset and when working with machine learning methods we typically need a few datasets for different purposes.

In this we use a excel sheet dataset , which contains 1500 datas. Each data contains 'Brand’, 'Ram’,’Rom’,’Processor' and 'Price’.

Step 3:Defining our data

The above image shows the datas and type of datas in our Dataset. As we previously said our data contains Ram,rom,price etc,. Now we define our data into arrays.

Now we plot our datas.A plot is a graphical technique for representing a data set, usually as a graph showing the relationship between two or more variables.

STEP 4: SPLITING THE DATASET

Separating data into training and testing sets is an important part of evaluating data mining models. ... By using similar data for training and testing, you can minimize the effects of data discrepancies and better understand the characteristics of the model. In our project we split 70% of our data for training and 30% for testing.

X_train - This includes your all independent variables,these will be used to train the model and rest will be used to test the model.

2). X_test - This is remaining portion of the independent variables from the data which will not be used in the training phase and will be used to make predictions to test the accuracy of the model.

3). y_train - This is your dependent variable which needs to be predicted by this model.

4). y_test - This data has category labels for your test data, used to test the accuracy between actual and predicted categories.

In my project I imported *train_test_split* from sklearn, as I felt this method was much easier.
Then the test and train size is specified.
I split the data into 70% test and 30% test. Which i specified as( test_size=0.3) in the above image.

Now we check the lenth of train and test sets using (len function ). Our data is splited correctly as we can see (len of x_train is 1049 and x_test is 450). And also we can see that the first 1049 values are not taken as train set , it took in random.

X_train:

X train is the train Dataset it contains Brand , ram , rom, processor. We can see that it doesnt take first 70% of our data,Datas should not be taken in order,it is should be taken in a random.

Y_train :

Y train dataset contains price , which we are going to predict.

STEP 5: Training our Model.

Model training in machine language is the process of feeding an ML algorithm with data to help identify and learn good values for all attributes .

We are importing LinearRegression from sklearn models. Linear Regression is a machine learning algorithm based on supervised learning. It performs a regression task. Regression models a target prediction value based on independent variables.

Plotting x_test:

fit() is for training the model with the given inputs (and corresponding training labels). evaluate() is for evaluating the already trained model using the validation (or test) data and the corresponding labels. Returns the loss value and metrics values for the model.

STEP 6 : Predicting

Model testing is referred to as the process where the performance of a fully trained model is evaluated on a testing set.

predict() is for the actual prediction.Now we are going to test our model.we give the brand and other varients as input and we recieve the predicted price as output. We can se that we gave bran(1),ram(4),rom(32) as inputs and the output predicted price is 39,431. Which 90% matches our Dataset.

Now we check the accuracy of our Dataset.

We plot as graph between RAM and PRICE . Just to check

We can see the Accuracy of our model : 0.973840. we get a high accuracy.

Thus in the project we:

  1. Imported req libraries
  2. Imported datset.
  3. Defined out datset.
  4. Split into train and test sets.
  5. Trained our sets.
  6. Evaluted or set.

Machine Learning provides smart alternatives to analyzing vast volumes of data. By developing fast and efficient algorithms and data-driven models for real-time processing of data, Machine Learning can produce accurate results and analysis.

Evaluating using sequential Model:

In this method we use sequential model to evaluate or datas.A Sequential model is appropriate for a plain stack of layers where each layer has exactly one input tensor and one output tensor. there are many layers in sequential model Input, dense, output layers.

Since we have more than one Input, Sequential model is not advisable and since we have more accuracy in LinearRegression we use that method.

--

--