Skip to main content

Featured

Main Challenges of Machine Learning and how to tackle them?

  Challenges for Machine Learning In this Article. we will be talking about the challenges of machine learning. As everything comes with some challenges packed with it, Machine Learning is no exception. As the main task is to select a learning algorithm and train it over data. The thing that might go wrong is either the " bad data "  or " bad algorithm " Let start with bad data  Low Quantity of Data for training For humans, if we have to classify between two new things given to us. we just have to see some of the examples and then, we are ready to go. But for Machine it's not quite easy task as the machine doesn't have a super talented brain like us. We may need thousands or even millions of images for complex problems ( unless we reuse another existing model ). Nonrepresentative Training data In order to make a good model. it is important for data to represent all the cases that can be possible.  For example, if we train a model to predict the gender of a...

Python List Comprehension & any,all

PYTHON


Python is a vast languages there is always somthing that you left behind if you are a beginner Let's Explore Some of that






1. List Compression

List compression is used as one liners in python they are sometimes very useful While we doesn't want to write a loop to fill list

For example : if we want to create a list of square of odd numbers from pre-existing list of numbers 1 to 10 

We consider doing this in two ways :

  • For loop

l1=[1,2,3,4,5,6,7,8,9,10] result=[] for item in l1: if item%2 != 0: result.append(item**2) print(result)

  • List Compression


l=[x**2 for x in range(10) if x%2!=0] print(l)


Result For Both :


[1,9,25,49,81] 


Let's see how it works

l=[result  loop  condition]


• The first one is result that you want 
• The second one is loop it's on you how you use it
• The third one is if else condition that you want to follow (optional)

Note : This also works with dictionaries ,tuples



Let's move on to second one

2. any , all keywords

any ,all keyword return a boolean they are generally used when we need to check multiple condition

For example : if we have a list of string and we need to check whether all the words are present in given string

We generally use two ways :

  • Check condition one by one


con=["hey","are","you"] phrase="hey what are you doing!" if con[0] in phrase and con[1] in phrase and con[2] in phrase: print(("All Words Match"))


  • Using "all"

con=["hey","are","you"] phrase="hey what are you doing!" if all(x in phrase for x in con): print("All Words Match")


Result for Both:


All Words Match 


We can also use "any" in similar way if we want to check if any of words of list con present in phrase


Comments

Popular Posts