codebasics / py Goto Github PK
View Code? Open in Web Editor NEWRepository to store sample python programs for python learning
Repository to store sample python programs for python learning
can u post the Logistic Regression (Multiclass Classification) execrise program
I would like to add some new programs as it would be helpful for anyone who sees this and also it will improve my python skills.
Hello,
Thanks for the lesson on linked list. I understood it completely.
This should work. Please update.
def insertAtBegin(self, data):
if self.head is None:
node = Node(data, self.head, None)
self.head = node
return
node = Node(data, self.head, None)
node.next = self.head
self.head.prev = node
self.head = node
I tried to add an element using insert_at_begining in empty double linked list and got an error
AttributeError: 'NoneType' object has no attribute 'prev'
class Node:
def __init__(self, data=None, next=None, prev=None):
self.data = data
self.next = next
self.prev = prev
class DoublyLinkedList:
def __init__(self):
self.head = None
def print_forward(self):
if self.head is None:
print("Linked list is empty")
return
itr = self.head
llstr = ''
while itr:
llstr += str(itr.data) + ' --> '
itr = itr.next
print(llstr)
def print_backward(self):
if self.head is None:
print("Linked list is empty")
return
last_node = self.get_last_node()
itr = last_node
llstr = ''
while itr:
llstr += itr.data + '-->'
itr = itr.prev
print("Link list in reverse: ", llstr)
def get_last_node(self):
itr = self.head
while itr.next:
itr = itr.next
return itr
def get_length(self):
count = 0
itr = self.head
while itr:
count+=1
itr = itr.next
return count
def insert_at_begining(self, data):
node = Node(data, self.head, None)
self.head.prev = node
print(self.head.prev)
self.head = node
def insert_at_end(self, data):
if self.head is None:
self.head = Node(data, None, None)
return
itr = self.head
while itr.next:
itr = itr.next
itr.next = Node(data, None, itr)
def insert_at(self, index, data):
if index<0 or index>self.get_length():
raise Exception("Invalid Index")
if index==0:
self.insert_at_begining(data)
return
count = 0
itr = self.head
while itr:
if count == index - 1:
node = Node(data, itr.next, itr)
if node.next:
node.next.prev = node
itr.next = node
break
itr = itr.next
count += 1
def remove_at(self, index):
if index<0 or index>=self.get_length():
raise Exception("Invalid Index")
if index==0:
self.head = self.head.next
self.head.prev = None
return
count = 0
itr = self.head
while itr:
if count == index:
itr.prev.next = itr.next
if itr.next:
itr.next.prev = itr.prev
break
itr = itr.next
count+=1
def insert_values(self, data_list):
self.head = None
for data in data_list:
self.insert_at_end(data)
if __name__ == '__main__':
ll = DoublyLinkedList()
# ll.insert_at_begining(10)
# ll.insert_values(["banana","mango","grapes","orange"])
# ll.print_forward()
# ll.print_backward()
# ll.insert_at_end("figs")
# ll.print_forward()
# ll.insert_at(0,"jackfruit")
# ll.print_forward()
# ll.insert_at(6,"dates")
# ll.print_forward()
# ll.insert_at(2,"kiwi")
ll.insert_at_begining('naveen')
ll.print_forward()
Hi ,
In doublylinkedlist.py
when I try to print this statement i'm getting error:
if name == 'main':
ll = DoublyLinkedList()
ll.insert_at_begining("mango")
plse try to use this insert_at_begining() first and see the case.
import pandas as pd
from matplotlib import pyplot as plt
import numpy as np
df = pd.read_csv(r"C:\Users\mdmar\Downloads\Thesis\Data/1024.csv")
#print(df.head())
#sizes = df['target'].value_counts(sort=1)
#print(sizes)
#Define dependent variable
Y = df['target'].values
Y=Y.astype('int')
#define independent variable
X = df.drop(labels=['target'], axis=1)
#Split dataset for train and test
from sklearn.model_selection import train_test_split
X_train, X_test, Y_train, Y_test=train_test_split(X,Y,test_size=0.30, random_state=30)
#print(X_train)
#Import Random Forest
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=70, random_state=40)
model.fit(X_train,Y_train)
prediction_test = model.predict(X_test)
print(prediction_test)
from sklearn import metrics
print("Accuracy:",metrics.accuracy_score(Y_test, prediction_test)*100,'%')
print(model.feature_importances_)
print(model.feature_importances_*100,'%')
Out : [1 1 1 0 0 1 1 1 1 1 1 1 0 1 1 0 0 1 1 0 1 0 0 0 1 1 1 1 1 1 0 1 0 1 0 1 1
1 0 0 1 1 1 0 0 0 1 1 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 0 0 1 0 1 0 0
0 0 1 1 0 0 0 1 0 0 1 1 0 0 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 1 1 0 1 0 0 0 0
0 0 1 0 0 0 0 1 0 1 0 0 1 1 1 0 1 0 1 0 0 1 1 1 1 1 0 0 0 0 1 0 1 0 0 1 1
0 0 0 0 1 0 1 0 0 1 1 1 0 0 0 1 0 1 1 1 1 1 1 1 1 0 0 1 0 0 0 1 0 0 1 0 0
0 0 0 1 1 1 0 1 1 1 0 1 1 1 1 1 0 0 1 1 0 0 0 1 0 0 1 0 1 0 0 0 0 1 1 1 0
0 0 0 1 0 0 1 1 1 1 1 1 0 1 0 1 0 0 1 0 0 0 0 1 1 0 1 1 1 0 0 1 0 1 1 0 0
1 1 1 1 1 0 1 0 0 0 1 0 0 1 0 1 0 0 0 1 0 0 1 1 1 0 1 0 0 1 0 0 0 1 0 1 1
1 0 0 1 0 1 0 0 1 1 1 1]
Accuracy: 97.72727272727273 %
[0.1031516 0.0358877 0.11881306 0.09649581 0.09640051 0.01116345
0.02173903 0.13786201 0.06464796 0.13677327 0.05528801 0.12177758]
[10.31516006 3.58876957 11.88130644 9.64958137 9.64005136 1.11634483
2.17390296 13.78620058 6.46479635 13.67732725 5.52880149 12.17775775] %
how to do hyperparameter tuning using K Fold cross-validation using this model
Hi,
When I use your code samples of panda, namely "import pandas.io.data as web", jupyter throws a module not found error. I tried replacing it with "import pandas_datareader.data but still getting some error. Request you to give me pointers how to fix this or please help with updated code samples. I have been following your python series and I had found it very useful.
We provide information about free online courses with certificates and Answers, Books, Guidance for courses, Free learning material etc.
Join us and grow together
Join here our Telegram Group Online Education
Need help here to generate updated db_dump.sql file. I did this sales insights series: https://www.youtube.com/playlist?list=PLeo1K3hjS3uva8pk1FI3iK9kCOKQdz1I9 Here in tutorial 9 I built a new dashboard that has new data. I think in one of the tables I added 2 or 3 columns. The issue is the columns were added directly to power BI. What we need to do now is,
13_read_write 中的代码在执行with open("poem.txt","r") as f:这句代码时,会报UnicodeDecodeError: 'gbk' codec can't decode byte 0x94 in position 659: illegal multibyte sequence 这样的错误
即使把代码更改成 with open("poem.txt",encoding='utf-8').read() as f: 也会报AttributeError: __enter__这样的错
明明 file 已经内置了对上下文管理协议的支持,可仍然要报错
File path: py/TechTopics/CodingBestPractices/coding_best_practices.md
Line of code: 130
Current: "return live above is so tricky and cryptic that it could give a headache to a person reading that code"
Correct: "return line above is so tricky and cryptic that it could give a headache to a person reading that code"
Amendment: live ---> line
if I want plot cost function take J(m) in y axis and m in x axis ?
##This is good*
I cant download the csv file I was following the you tube lecture of data science but I was unable to download the csv file from it please help I need the file for practicing
#code
Here is the link, where exercise figure is not visible. Kindly fix that.
Link: https://github.com/codebasics/py/blob/master/matpltlib/7_save_chart/7_saving_chart_to_file.ipynb
plz
If self.right is None:
return self.left
Example:
data_elements = [17, 5, 2, 23, 18, 34]
Try to delete element 5
should be: exp[3] + 200
Hi
I got your code from multiprocessing_pool to run as an example.
I copied exactly but in Jupyter i get nothing, no finished print is shown. (kernel keeps busy).
Thanks for your help.
initializing
Following code from this file in celebrity recognition project does not work:
face_cascade = cv2.CascadeClassifier('./opencv/haarcascades/haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('./opencv/haarcascades/haarcascade_eye.xml')
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
faces
Error:
---------------------------------------------------------------------------
error Traceback (most recent call last)
<ipython-input-9-17af89ccf870> in <module>()
4 # eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_eye.xml')
5
----> 6 faces = face_cascade.detectMultiScale(gray, 1.3, 5)
7 faces
error: OpenCV(4.1.2) /io/opencv/modules/objdetect/src/cascadedetect.cpp:1689: error: (-215:Assertion failed) !empty() in function 'detectMultiScale'
Excellent work and excellent suggestions, thank you for sharing.
It struck me that your choice of career tracks might be somewhat restrictive.
Cloud, Automation, Cybersecurity, and DevOps could be similarly desirable career tracks options. Also, there might be others that I missed here.
In fact, it would be great if you could outline a DevOps 2020 step-by-step roadmap or give any pointer to one that you consider valuable.
I first created an array: (3 dimensional array)
nlist= [[[1,2,3],[4,5,6],[7,8,9]],[[10,11,12], [13,14,15], [16,17,18]],[[19,20,21],[22,23,24],[25,26,27]]]
import numpy as np
narray = np.array(nlist)
Then I converted it into a dataframe using: (3 dimensional DataFrame)
import pandas as pd
df = pd.DataFrame.from_records(narray)
So I basically converted a 3-dimensional array to a 3-dimensional dataframe.
Now when I try to get it back as an array using:
new_list = np.array(df)
Now this returns a 2-dimensional array. But I want the original 3-dimensional array. What do I do?
If we run the file on the system, there is no issue but when we deploy it on Heroku and try to remove the image after uploading, an error popup is shown.
Try it yourself here - https://kanakmi-dogvscat.herokuapp.com/
I have actually resolved this issue, please assign it to me so that I can change it here as well.
The website with the removed issue can be found here - https://animevscartoon.herokuapp.com/
The linear regression notebooks do not contain the ##matplots. This makes me question how or why the linear regression was chosen in the first place?
#24
OneHotEncoding
I watch a great marketplace on my country.
I live in Ecuador and the country have good opportunities on the turism market.
I have a idea to connect the people, but I need some help.
I have basic skills on development. Thanks.
Psdt: great business
In the age column, there are 177 Nan. How to deal with whether should I delete them or put the mean of age column??
column names in CSV file have spaces in them which certainly makes it impossible to call using '.' also when you edit a csv file it changes it seems to change its formatting and everything just messes up.
suppose we need to find price of a house with 2 baths and 3 bhk .its price is lower than with 2 baths and 2 bhk.
One more suggestion:
if put absurd values like:
1000sqft and 50 bhk then it should return not available but this model is predicting the price of this also. And suppose if we searched for 1000 sqft with 1000 bhk I know that is invalid but this model shows price in negative also. I think this should be corrected.
In the Data Structures folder, the folder numbering starts from 2 and goes up to 10 with number 4 and number 9 occurring for more than one folders. The problem is that there is no folder numbered '1' in the entire list. This sets a beginner back, and misguides them about the level of difficulty that I assumed each number carries.
Consider renumbering the folders with the Arrays folder numbered as 1.
for Experience column, why you have filled empty values to zeros.
why mean values are not filled like column test_score
try:
print(emp.id)
except AttributeError: !!!!!!!!!
print("emp.id is not defined")
Everyone, I am desperately looking for some volunteers who can help me come up with basic python exercises. This should be an easy as well as fun task for you. Whoever contributes the most will get 30 min zoom/watsapp conversation with me. I can give you career guidance or answer any questions you have.
Here is what I am looking for,
Hi, first of all, thanks for this page it helped me a lot, but I noticed you forgot to import numpy and cossval_score after the title Aproach 2.
I used it like this:
import numpy as np
from sklearn.model_selection import cross_val_score
That's all
current:
factorial(5) : 60
expected:
factorial(5) : 120
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.