You are a data scientist with a strong background in machine learning and programming. You have experience building regression models from scratch and have a deep understanding of polynomial regression. You are skilled in Python programming and have a knack for implementing algorithms without relying on libraries or packages. You have a collection of personal projects, code repositories, and blog posts where you have demonstrated your ability to build polynomial regression models from scratch. Your expertise in both machine learning and Python programming makes you the ideal agent to help someone build a Polynomial Regression Model in Python without using any libraries or packages. You can provide step-by-step guidance, code snippets, and valuable insights to ensure a successful implementation.
i write a code please edit this for my task is a  x_data and y import from int(input("  ")).
when user run code. ask number of x and for number of x generate x[i] and int(input("  ")) for any x[i].after that y import and after degree import.
my sample code:
1:
# Function to check if a matrix is singular (determinant is zero)
def is_singular(matrix):
    n = len(matrix)
    for i in range(n):
        if matrix[i][i] == 0:
            return True
    return False

# Function to invert a matrix (Gauss-Jordan elimination method)
def invert_matrix(matrix):
    n = len(matrix)
    augmented = [[matrix[i][j] if j < n else (1 if i == j - n else 0) for j in range(2 * n)] for i in range(n)]

    for i in range(n):
        diag = augmented[i][i]
        if diag == 0:  # Check for singularity
            raise ValueError("Matrix is singular and cannot be inverted.")
        
        for j in range(2 * n):
            augmented[i][j] /= diag

        for k in range(n):
            if k != i:
                factor = augmented[k][i]
                for j in range(2 * n):
                    augmented[k][j] -= factor * augmented[i][j]

    return [[augmented[i][j] for j in range(n, 2 * n)] for i in range(n)]

# Main function to take input from the user and run the polynomial regression
def main():
    # Step 1: Ask the user how many independent variables there are
    num_x = int(input("Enter the number of independent variables: "))

    # Step 2: Ask for input values for each independent variable
    X_data = []
    for i in range(num_x):
        x_values = list(map(float, input(f"Enter the values for x{i+1} (space-separated): ").split()))
        X_data.append(x_values)
    
    # Step 3: Ask for input values for the dependent variable (y)
    y = list(map(float, input("Enter the values for the dependent variable y (space-separated): ").split()))
    
    # Step 4: Ask for the degree of the polynomial
    degree = int(input("Enter the degree of the polynomial: "))
    
    # Step 5: Perform polynomial regression
    try:
        beta = polynomial_regression_auto(X_data, y, degree)
    except ValueError as e:
        print(e)
        return
    
    # Step 6: Output the coefficients (beta)
    print("\nCoefficients (beta):", beta)
    
    # Step 7: Predict the values using the model
    y_pred = predict_auto(X_data, beta, degree)
    
    # Step 8: Output the predicted values
    print("\nPredicted values (y_pred):", y_pred)

# Run the main function
if __name__ == "__main__":
    main()

2:
def print_matrix(matrix, name):
    print(f"\n{name}:")
    for row in matrix:
        print([f"{x:.6f}" for x in row])

def matrix_multiply(A, B):
    result = [[sum(a * b for a, b in zip(A_row, B_col)) 
               for B_col in zip(*B)] 
               for A_row in A]
    return result

def transpose(matrix):
    return list(map(list, zip(*matrix)))

def invert_matrix(matrix):
    n = len(matrix)
    augmented = [row[:] + [1 if i == j else 0 for j in range(n)] for i, row in enumerate(matrix)]
    
    for i in range(n):
        # Find maximum pivot
        pivot_value = abs(augmented[i][i])
        pivot_row = i
        for j in range(i + 1, n):
            if abs(augmented[j][i]) > pivot_value:
                pivot_value = abs(augmented[j][i])
                pivot_row = j
                
        # Swap rows if necessary
        if pivot_row != i:
            augmented[i], augmented[pivot_row] = augmented[pivot_row], augmented[i]
            
        pivot = augmented[i][i]
        if abs(pivot) < 1e-10:
            raise ValueError(f"Matrix is singular, cannot invert. Pivot at row {i} is {pivot}")
            
        # Divide row by pivot
        for j in range(i, 2 * n):
            augmented[i][j] /= pivot
            
        # Eliminate column
        for j in range(n):
            if i != j:
                factor = augmented[j][i]
                for k in range(i, 2 * n):
                    augmented[j][k] -= factor * augmented[i][k]
    
    return [row[n:] for row in augmented]

def create_polynomial_features(X_data, degree):
    x_values = X_data[0]
    n_samples = len(x_values)
    features = []
    
    for d in range(degree + 1):
        features.append([x ** d for x in x_values])
    
    return features

def polynomial_regression(X_data, y, degree):
    # Create polynomial features
    X = create_polynomial_features(X_data, degree)
    print_matrix(X, "Feature Matrix X")
    
    # Convert y to column vector
    y = [[val] for val in y]
    
    X_T = transpose(X)
    print_matrix(X_T, "X Transpose")
    
    X_T_X = matrix_multiply(X_T, X)
    print_matrix(X_T_X, "X^T * X")
    
    try:
        X_T_X_inv = invert_matrix(X_T_X)
        print_matrix(X_T_X_inv, "Inverse of X^T * X")
    except ValueError as e:
        print(f"Error during matrix inversion: {e}")
        raise
    
    X_T_y = matrix_multiply(X_T, y)
    print_matrix(X_T_y, "X^T * y")
    
    beta = matrix_multiply(X_T_X_inv, X_T_y)
    return [b[0] for b in beta]

def predict(X_data, beta, degree):
    X = create_polynomial_features(X_data, degree)
    predictions = matrix_multiply(transpose(X), [[b] for b in beta])
    return [p[0] for p in predictions]

def main():
    try:
        # Get input data
        num_x = int(input("Enter the number of independent variables: "))
        if num_x != 1:
            print("This implementation currently supports only one independent variable.")
            return

        x_values = list(map(float, input("Enter the values for x1 (space-separated): ").split()))
        X_data = [x_values]
        
        y = list(map(float, input("Enter the values for the dependent variable y (space-separated): ").split()))
        
        if len(x_values) != len(y):
            print(f"Error: Number of x values ({len(x_values)}) must match number of y values ({len(y)})")
            return
        
        degree = int(input("Enter the degree of the polynomial: "))
        
        # Perform regression
        beta = polynomial_regression(X_data, y, degree)
        
        # Print results
        print("\nCoefficients (beta):", [f"{b:.6f}" for b in beta])
        
        # Make predictions
        y_pred = predict(X_data, beta, degree)
        print("\nPredicted values:", [f"{yp:.6f}" for yp in y_pred])
        
        # Calculate R-squared
        y_mean = sum(y) / len(y)
        ss_tot = sum((yi - y_mean) ** 2 for yi in y)
        ss_res = sum((yi - yp) ** 2 for yi, yp in zip(y, y_pred))
        r_squared = 1 - (ss_res / ss_tot)
        print(f"R-squared: {r_squared:.6f}")
        
    except ValueError as e:
        print(f"Error: {e}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

if __name__ == "__main__":
    main()