0

I am doing a machine learning project in materials science, this code asks me to choose files to upload, but when I name the files it comes up with an error message. The beginning of the code (and relevant bits) are included below:

import xlrd
import re
import numpy
from sklearn import svm
from sklearn import preprocessing
from sklearn import tree
from sklearn.ensemble import RandomForestClassifier
import random
import os
from xlutils.copy import copy
import xlsxwriter
import graphviz


def main():

    pastExperiments = StoredData()
    response = input('Do you wish to use continuous representation of discreet data if available data? y or n\t')
    if response == 'y':
        pastExperiments.useContinuousRepresentation = True
    else:
        pastExperiments.useContinuousRepresentation = False

    response = input('Do you want to choose import data? y or n\t')
    if response == 'y':

        while response == 'y':
            nameOfFile = input('What is the name of the file you wish to import.\t')
            pastExperiments.importFile('./Input/' + nameOfFile)
            response = input('Do you wish to import additional data? y or n\t')
        #At this point all training data should have been imported.

    else:
        folder = os.fsencode('Input')
        for inputFile in os.listdir(folder):
            fileName = os.fsdecode(inputFile)
            if fileName.endswith(".xlsx"):
                pastExperiments.importFile('./Input/' + fileName)
            else:
                continue

Here is the error message I get:

FileNotFoundError: [Errno 2] No such file or directory: './Input/Sample_info_.xlsx'

Thanks!

GreenMatt
  • 18,244
  • 7
  • 53
  • 79
Chi
  • 11
  • 4
  • The error is telling you that the file ./Input/Sample_info_.xlsx does not exist. Are you absolutely sure that's the correct name and directory? Beyond that, we'd need to at least see the importFile method to be able to help. – GreenMatt Dec 19 '18 at 15:13
  • The file name is correct as I saved it in "My Documents". I also did not write this code, so what I have posted is all I know of the method. I know it is a pathing error but I don't know what to do about this. I am also completely new to python and machine learning. – Chi Dec 19 '18 at 16:44
  • This doesn't really have to do with machine learning, and a similar problem can happen with any language. It seems that the problem is that the program is looking in a specific subdirectory (folder) for the input file, but the file is in a different directory. I suspect the `Input` directory is a subdirectory of the directory from which you run the program. Copy your data file into that directory and try again. – GreenMatt Dec 19 '18 at 17:09

0 Answers0