Skip to main content

A simple module for using Machine Learning in your code.

Project description

Installation - How to install


The easiest way to install maclearn is using pip. Open your teminal and enter -
pip install maclearn



Instruction - How to use maclearn


Using maclearn in your project is simple enough. Currently, you'll find only 2 algorithms in this module. We are working to develop more.


Reading Excel Files (.csv/.xlsx)

Reading excel files using maclearn is quite easy.
Let's say we want to read this file (PizzaPrice.csv) -
Size  Price
 6  350
 8  775
 12  1150
 14  1395
 17  1648
 18  1675

The file may be in .xlsx or .csv format but the extension doesn't matter. Here's how to read it -
For .csv format -
        import maclearn # importing the module
        
        filename = "PizzaPrice.csv"  # Initialize the directory
        file = maclearn.csv(filename)  # Create a csv object
        data = file.data()  # Read the data and store it as a list
        print(data)  # Print the data


            Result - [[6, 8, 12, 14, 17, 18], [350, 775, 1150, 1395, 1648, 1675]]
  


For .xlsx format -

            import maclearn # importing the module
            
            filename = "PizzaPrice.xlsx"  # Initialize the directory
            file = maclearn.xlsx(filename)  # Create a xlsx object
            data = file.data()  # Read the data and store it as a list
            print(data)  # Print the data
  

            Result - [[6, 8, 12, 14, 17, 18], [350, 775, 1150, 1395, 1648, 1675]]
  


If you want, you can put file.data() in the fit method of GaussianNaiveBayes or LinearRegression in order to fit the data to your model from an excel file




Gaussian Naive Bayes Classifier

First create the object GaussianNaiveBayes()...
Then call the fit() method to fit the data to your model.
Note: Your data must be in this format - [Feature1, Feature2, Feature3, Label]...
Here, you can use as many features as you want...
After that, simply call the predict(*Features) method to predict the label....
You can calculate the F1 Measure for your model by simply calling the f1_measure() method.
You can also calculate the specificity for your model by simply calling the specificity() method.
Example:
        import maclearn # Importing the module
        # Features
        Outlook = ["Sunny", "Sunny", "Cloudy", "Sunny", "Cloudy", "Cloudy", "Sunny"]
        Temperature = ["Cold", "Warm", "Warm", "Warm", "Cold", "Cold", "Cold"]
        Routine = ["Indoor", "Outdoor", "Indoor", "Indoor", "Indoor", "Outdoor", "Outdoor", "Outdoor"]
        WearCoat = ["No", "No", "No", "No", "Yes", "Yes", "Yes"] # Labels
        
        # You can also import the data from an excel file
        Features = [Outlook, Temperature, Routine, WearCoat] # Putting all features in a list
        
        model = maclearn.GaussianNaiveBayes()  # Creating the object
        model.fit(Features) # Fit the data into the model

        # Should we wear coat, if our feature set is cloudy, warm and outdoor?
        print(model.predict("Cloudy", "Warm", "Outdoor")) # Predict the label
        f1_value = model.f1_measure() # Calculate the F1 measure value for the model
        specificity = model.specificity() # Calculate the specificity for the model
        print(f1_value * 100, "%") # print F1 measure value in percentage
        print(specificity * 100, "%") # print specificity in percentage



Linear Regression with numerical analysis

First create the object - LinearRegression()...
Then call the fit(x, y) method to fit the data to your model.
This model is for single variable linear regression. So your data must be in this format - X=[2,3,4], Y=[5,6,7]
Then, just call the predict(x) method with the argument of x value to predict the y value...
You can also calculate the R-Squared value by simply calling r_squared() method.
Example:
        import maclearn # Importing the module

        # You can also import the data from an excel file
        Size = [6, 8, 12, 14, 18] # Size of Pizza in inches (Independent Variable)
        Price = [350, 775, 1150, 1395, 1675] # Price of Pizza in Taka (Dependent Variable)
                    
        model = maclearn.LinearRegression()  # Creating the object
        model.fit(Size, Price) # Fit the data into the model

        predicted = model.predict(17) # Predicted the price of 17 inches pizza
        accuracy = model.r_squared() # Calculate the R-Squared value for the model

        print(predicted) # Print the predicted value
        print(accuracy * 100, "%") # Print the R-Squared value in percenntage



Lisence


This module is completely free and open source. You can use and modify to improve the module if you want ;)
Any suggestion will be highly appriciated. Gmail - neural.gen.official@gmail.com

Created by Sajedur Rahman Fiad

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

MacLearn-1.0.1.tar.gz (5.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page