Sort by

recency

|

216 Discussions

|

  • + 0 comments

    I have a laptop from Dell Company which has 8 GB RAM and 256 SSD hard disk. Its battery was working very well for the first year. I had taken out four to five times but suddenly it has stopped working. Now it has taken out 20 to 25 minutes. I don't understand what the problem is. If any of you know, please guide me. You can contact me for more information.

  • + 0 comments

    I've found it useful to create a scatter plot (plt. scatter(X,Y))to understand the shape before selecting a model

  • + 0 comments

    Auto locksmith training offers hands-on experience in key cutting, lock repairs, and security solutions for vehicles. Master the skills needed to tackle car lockouts, transponder key programming, and ignition repairs. With expert instructors and a comprehensive curriculum, this training prepares you for a successful career in the automotive locksmith industry. Enroll now in auto locksmith training to unlock new opportunities and enhance your skills in a high-demand field!

  • + 0 comments

    Using least square regression through definition (matrix inversions, dot products and transpose), no library:

    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    import pandas as pd
    import numpy as np
    from scipy import optimize
    #import matplotlib.pyplot as plt
    from io import StringIO
    
    
    if __name__ == '__main__':
        timeCharged = float(input().strip())
    
        # Read the data using pandas
        data = pd.read_csv('trainingdata.txt', header=None, names=["TimeCharged", "TimeLasted"])
        
        # training data: Range when not fully charge range
        index_values = data.query("TimeCharged <= 4.01").index.tolist()
        x = data.TimeCharged[index_values]
        y = data.TimeLasted[index_values]
    
        # Equation to be solved from book https://pythonnumericalmethods.studentorg.berkeley.edu/notebooks/chapter16.02-Least-Squares-Regression-Derivation-Linear-Algebra.html
        # y = b1 * f1(x)
       
        # A Matrix
        # Only one linear basis function used. Important: Method allows any kind and number of basis function, as long as beta params are constants
        # Basis function is  evaluated at the input measured values. In this case f1(x) = x 
        A = np.array(x).reshape(-1,1)
    
        # Y Matrix: Output measured values
        Y = np.array(y).reshape(-1,1) 
    
        # Here is where the magic happends: Least square regression to find beta parameters
        beta_params = np.linalg.inv(A.T @ A) @ A.T @ Y
        
        
       # Make prediction
        if timeCharged > 4.01:  # Battery fully charged
            print(8)  
        else:
            predicted_time = timeCharged *  beta_params[0][0]
            print(predicted_time)  # Output the predicted battery life
    
  • + 0 comments

    Even not strictly necessary for this challenge, i got back to theory and implentation of least square regression, as this method opens solutions for a lot of problems, including this one.

    I super recommned this book: https://pythonnumericalmethods.studentorg.berkeley.edu/notebooks/chapter16.04-Least-Squares-Regression-in-Python.html

    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    import pandas as pd
    import numpy as np
    from scipy import optimize
    from io import StringIO
    
    
    if __name__ == '__main__':
        timeCharged = float(input().strip())
        
        # Read the data using pandas
        data = pd.read_csv('trainingdata.txt', header=None, names=["TimeCharged", "TimeLasted"])
    
        # training data: Range when not fully charge range
        index_values = data.query("TimeCharged <= 4.01").index.tolist()
        x = data.TimeCharged[index_values]
        y = data.TimeLasted[index_values]
       
        # create basis functions for least square regression 
        def basis_func_lin (x, b1):
            return b1 * pow(x,1)
            
        # or
        def basis_func_quad (x, b1, b2):
            return b1 * pow(x,1) + b2 * pow(x,2)
    
        #choose func
        func = basis_func_lin
        
        # do training (least square regression)
        beta_params, covariance = optimize.curve_fit(func, x, y)
        
       # Make prediction
        if timeCharged > 4.01:  # Battery fully charged
            print(8)  
        else:
            predicted_time = func(timeCharged, *beta_params)
            print(predicted_time)  # Output the predicted battery life