Skip to main content

Posts

Machine Learning — Supervised, Unsupervised, and Reinforcement — Explanation with Example

🤖 Let's take an example of machine learning and see how it can be performed in three different ways — Supervised, Unsupervised, and Reinforcement. We want a program to be able to identify apple in pictures Supervised Learning You will create or use a model that takes a set of pictures of apple and it analyses the commonality in those pictures. Now when you show a new picture to the program, it will identify whether it has an apple or not. It can also provide details on how confident is the program about it. Unsupervised Learning In this method, you create or use a model that goes through some images and tries to group them as per the commonalities it observes such as color, shape, size, partern, etc. And now you can go through the groups and inform the program what to call them. So, you can inform the program about the group that is apple mostly. Next time you show a picture, it can tell if an apple is there or not. Reinforcement Learning Here the model you create or...

How to go from Andheri in Mumbai to Pune by Road?

🚌 Here is how you go from Andheri in Mumbai to Pune by Road. Take an auto or walk to Bisleri Bus Stop Take a Bus for Pune. It cost me ₹400 This is the best way to travel to Pune from Andheri in Mumbai by Road on bus. My friends use car pooling on bla bla car. That is cheaper but will require coordination + could be a risk for women.

How to go Andheri from Pune by road?

🛣️  I am putting out how I managed to go from Pune to Andheri in Mumbai. I had to reach Zipgrid office in Andheri. It is near MagicBricks Weh Metro Station. Took Shivneri Bus from Indira College, Wakad that was going to Borivali via Powai. I get down at Jogeshwari. The bus cost me 560. I would suggest to take non-Shivneri, it is cheaper. From Jogeshwari I take an auto to Magicbricks Weh Metro Station. That cost me 33 rupees. That is where is Zipgrid Office. The firm is also known as MyAashiana. It is in the building opposite to PVR. The building's name is The Summit Business Bay by Omkar. Now you know how to go Andheri in Mumbai from Pune by road. You could also opt for bla bla car or anything where you can share transport, it will cost you similar.

What is Model View Controller (MVC)?

💻 Model View Controller (MVC) is an architectural paradigm. It is popular because a lot of frameworks use it, such as Ruby on Rails, cakephp, and Django. Clients are generally browsers. It is basically an envirnment users use to access the application. Servers are where programs are run to fulfill the needs of a client. Database is where data is stored. Servers can pull data from database, processes it as per the needs of the client and sends to the client where is it is displayed to the user. In MVC architecture, separate files take care of these three parts. Model takes care of the Database related activities View takes care of the Client Controller takes care of the Server View listens to the Controller and Controller talks to the Model and vice versa. At all times Controller is there in between the two. There is no direct connection between View and Model.

Python — With Statement — A Context Manager

🐍 When you open a file, you are required to close it too. If between your open statement and close statement there are n other statements, and in any of the statement an error occurs, your program won't reach the point to close the file. It will remian opened. Try this to understand the issue. Input f = open('some_file.txt', 'a') f.readlines() f.close() Output UnsupportedOperation Error Input f.write('add more text to test if file is open') Output 37 The above example shows that at line 2 an error occurred and the program didn't reach line 3 to close the file. Later we wrote something to the file and it worked, which means the file is still open. Run the close statement again to close it. Input f.close() Protect the file with try/except/finally One solution to this is use of try/except/finally statements as follows. Input f.open('some_file.txt', 'a') try: f.readlines() except: print('An exception was raised.') finally: ...

Python - List - Append, Count, Extend, Index, Insert, Pop, Remove, Reverse, Sort

🐍 Advance List List is widely used and it's functionalities are heavily useful. Append Adds one element at the end of the list. Syntax list1.append(value) Input l1 = [1, 2, 3] l1.append(4) l1 Output [1, 2, 3, 4] append can be used to add any datatype in a list. It can even add list inside list. Caution: Append does not return anything. It just appends the list. Count .count(value) counts the number of occurrences of an element in the list. Syntax list1.count(value) Input l1 = [1, 2, 3, 4, 3] l1.count(3) Output 2 It returns 0 if the value is not found in the list. Extend .count(value) counts the number of occurrences of an element in the list. Syntax list1.extend(list) Input l1 = [1, 2, 3] l1.extend([4, 5]) Output [1, 2, 3, 4, 5] If we use append, entire list will be added to the first list like one element. Extend, i nstead of considering a list as one element, it joins the two lists one after other. Append works in the following way. Input l1 = [1, 2, 3] l1.append([4, 5]) Output...

Python - Dictionary - Comprehension, Iteration, Items, Keys, Values

🐍 Advance Dictionaries There is very little one can do with dictionaries. Dictionaries are very useful, but because of their relatively complex state, very few modifications can be done in simple ways. Here are a couple of things you do with dictionaries. Dictionary Comprehension Just like List Comprehensions, Dictionary Data Types also support their own version of comprehension for quick creation. It is not as commonly used as List Comprehensions. Here is an example of Dictionary Comprehension. Input d = {x:x**2 for x in range(10)} d Output {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81} Another example where we pick keys from one place and values from another. Input d = {k:v**2 for k,v in zip(['a','b','c','d','e','f','g','h','i','j'],range(10))} d Output {'a': 0, 'b': 1, 'c': 4, 'd': 9, 'e': 16, 'f': 25, 'g': 36, 'h': 49, ...