EME 210
Data Analytics for Energy Systems

Machine Learning & Black Box

PrintPrint

Read It: Machine Learning & Black Box

Machine Learning

[00:13:34.59] We'll start with neural networks here. So, this is just elaborating on these different kinds of learning-- so supervised learning and unsupervised learning and reinforcement learning. And I already defined what those are. But let me just focus on the supervised learning part here.  

[00:13:50.45] You'll see that three of these sub boxes are dealing with neural networks. And so, what I'm going to talk about neural networks in general and then go on to focus on feed forward neural networks. Bear in mind that there are some other different kinds of neural networks here.  

[00:14:11.90] And so again, because these are all forms of supervised learning, we've got some input, some numbers, let's say, as our input. These are our x's. And they go into some network. The analogy here is our multiple regression model-- our sets of x's and their coefficients. That would be the analogy, but it's not exactly the same thing.  

[00:14:35.02] And then ultimately, we get a prediction. And then because it's supervised learning, we have data on the predicted values, and so we want to see how well these agree. And so, what we need to do is tune the inner workings of this, tune the network, until our output predictions match our observed y values or our observed predictions, our ground truth.  

[00:15:07.39] So we want to minimize the disparity between these two objects here, which is what we were doing in linear regression, also. When we flashback all the way to the simple linear model, what were we trying to minimize? We were trying to find the beta 1, the slope, and the intercept, beta 0, then minimized the sum of square errors. Remember that?  

[00:15:36.72] Basically, minimize the average amount of the distance between the data points in the line. So, it's a similar thing here, except we're not dealing with just a simple line. We don't just have a beta 1 and a beta 0. We're going to have a whole bunch of different things in here that we can adjust, and we want to tune these so that the difference between these is minimized. So same kind of objective, but we just have more tools to work with that.  

[00:16:08.45] Convolutional neural networks-- same idea, except the networks are more set up to deal with images, image data. And so, we'll focus on different segments of an image at the same time and try to identify what subset is a dog and what subset's a cat and things like that. And then recurrent neural networks are good for time series data, like audio data or weather data that's happening over time, where you're dealing with a sequence of values that have some correlation with each other over time.  

Enter image and alt text here. No sizes!
ADD IMAGE: L27:Slide 3B
Enter image credit here

BLACK BOX 

[00:16:48.25] So we're going to focus on feed forward networks. This is kind of the most general basic tool and the most-- the next logical step forward above regression. Sound good, guys?  

[00:17:06.61] One thing that I want to make a comment on, though, is that neural networks, and machine learning in general, are often referred to as a black box approach, meaning that while with linear regression and multiple linear regression, we get that nice output from the stats model that tells us about exactly what each coefficient value is and what its t-statistic is and its p-value-- basically, how good each coefficient is and how good each explanatory variable is and how powerful it is and overall how good the model is fitting-- we have all these diagnostics.  

[00:17:45.44] And we have complete discretion over how we design that multiple regression model. And that's not true of neural networks. We can set up the network, and we can set up the general framework and describe how many different terms we want. But ultimately, when all is said and done, we're going to get something that we can't really go in and interrogate and say-- at the end of the day, it's going to be very hard to say, oh, I'm glad I had this as an input. That turned out to be a very valuable predictor of these y's.  

[00:18:22.74] No, we're just going to throw a bunch of stuff in and minimize this difference. And if this difference is minimized, then call it a day. It doesn't matter if we threw in a bunch of useless terms, a bunch of useless inputs. It doesn't matter if we failed to put in some powerful predictors.  

[00:18:42.05] But it does. It does matter, but the black box does not care. And we wouldn't have any way of telling as such without redoing the whole thing again and comparing the two different black boxes.  


Try It: OPTION 1 GOOGLE COLAB

  1. Click the Google Colab file used in the video here.
  2. Go to the Colab file and click "File" then "Save a copy in Drive", this will create a new Colab file that you can edit in your own Google Drive account.
  3. Once you have it saved in your Drive, try to implement the following code to import a file of your choice by mounting your Google Drive:

Note: You must be logged into your PSU Google Workspace in order to access the file.

from google.colab import drive

drive.mount('/content/drive')

import pandas as pd

df = pd.read_csv('yourfilename.csv')

df # print the dataframe

Once you have implemented this code on your own, come back to this page to test your knowledge.


OPTION 2 : DATACAMP

 Try It: OPTION 2 DataCamp - Apply Your Coding Skills

Dictionaries are a quick way to create a variable from scratch. However, their functionality is limited, so we will often want to convert those dictionaries into DataFrames. Try to code this conversion in the cell below. Hint: Make sure to import the Pandas library.

# This will get executed each time the exercise gets initialized. # Create a Simple Dictionary mydict = {'Name':['Amy', 'Bob', 'Clair', 'Daisy'], 'Birthday':['9/3/1991', '4/21/1988', '4/21/1990', '11/11/1989'], 'Age':[31, 34, 32, 33]} # convert the dictionary to a DataFrame # print the values in the 'Birthday' column # Create a Simple Dictionary mydict = {'Name':['Amy', 'Bob', 'Clair', 'Daisy'], 'Birthday':['9/3/1991', '4/21/1988', '4/21/1990', '11/11/1989'], 'Age':[31, 34, 32, 33]} # convert the dictionary to a DataFrame import pandas as pd mydataframe = pd.DataFrame(mydict) # print the values in the 'Birthday' column mydataframe['Birthday']


Assess It: Check Your Knowledge

Knowledge Check (replace question)