게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
파이썬 잘하는 횽님들 좀 도와줘요
게시물ID : jisik_121052짧은주소 복사하기
작성자 : 허허54752;
추천 : 0
조회수 : 263회
댓글수 : 0개
등록시간 : 2012/03/08 15:10:56
파이썬 프로그래밍 숙제인데...
잘 하고 있는지 모르겠네요 ㅎㅎㅎ


일단 이게 데이타 파일이에요.
4
5

2 3 4 1 1
5 4 2 5 4
4 5 3 1 3
1 1 1 5 5
data. txt


1)write a 코드 called open_file_forassignment2 that takes in the name of 
the input file and opens it. the file is returned back from the 코드
여기서 일단 파일을 열고, 오픈을 한다음. 그냥 리턴을 해야되는지, 아니면 스트립을 해야 하는지
모르겠네요..


def open_file_for_assignment2():
data=open('data.txt','r')
for line in data:
line = line.strip()
print len(line)

2) write a 코드 called 'read_user_movie_matrix' that takes in as input the 
file that is opened from step 1 above and returns back a nested list which is 
the user_movie_matrix. this 코드 must read the data from the input file.
여기서 요점은 "nested list" 로 리턴이 되야 한다는건데..
내가 맞게 했는지 모르겠네요

def read_user_movie_matrix(fileObject):
nestedList=[]
numberOfUsers=int(fileObject.readline())
numberOfMovies=int(fileObject.readline())
blankLine=fileObject.readline()
for singleRow in fileObject:
removeWhiteSpace=singleRow.strip()
row_in_list=removeWhiteSpace.split()
nestedList.append(row_in_list)
return nestedList

3) write a 코드 called 'calculate_similarity_score' and returns back the 
similarity score btw pair of users. (you are free to choose whatever you like as 
input to the 코드)

similarity score 는 1/(1+ 유저1,유저2) 의 유클라디언 거리 
즉 
루트 ((x2-x1)제곱 + (y2-y2)제곱 )
그래서 helper 코드 을 만들어 봤어요

def distance_score(user1,user2):
user1=file.readline(3) 요기서 유저1이랑 유저2 얘네들을 define 해줘야 되는데..
user2=file.readline(4) 어떻게 하는지 잘 모르겠네요..
distance = sqrt((user1[1]-user2[1])**2+(user1[2]-user2[2])**2))
return distance
def calculate_similarty_score(user1,user2):
user1=file.readline(3) 위에랑 마찬가지로..ㅠ_ㅠ 어찌 define 을 해야 하는지...
user2=file.readline(4)
similarity_score =1.0/(1+distance_score(user1,user2))
return similarity_score

4) write a 코드called 'populate_user_user_matrix' that creates a 
user_user_matrix and returns it. (you are free to choose whatever you like as 
input to the 코드)
이거는 수열을 만들어라 하는데.. 이렇게 만들면 되는건지... 사실 이부분부터 되게 막힘..ㅠ_ㅠ
def populate_user_matrix(user1,user2):

matrix1=()
matrix2=()
for num1 in user1:
append.int(matrix1)
for num2 in user2:
append.int(matrix2)
return matrix2
return matrix1

5) write a 코드 called 'print_user_user_matrix' that prints the 
user_user_matrix on the screen (you are free to choose whatever you like as 
input to the 코드)
이건 4번이랑 뭐가 틀린지 말 모르겠음.. 이것도 유저-유저 간의 수열을 작성하라는데..
프린트를 쓰는게 다인지...
def print_user_user_matrix(user1,user2):
user1=file.readline(3)
user2=file.readline(4)
print matrix1
print matrix2

6) write a 코드 called 'most_similar_pair_of_users' that prints the most smilar
pair of users on the screen (you are free to choose whatever you like as 
input to the 코드)
이거는 유저간의 취향이 가장 비슷한 즉 위에 3번의 similarity score 가 가장 작은 페어를 찾는건데
이렇게 여러가지의 경우의 수가 나올 수 있는데 .. 이건 맞게 하는게 맞는지...
#ie) 1,2 or 1,3, or 1,4 or 1,5, or 2,3, or 2,4, or 2,5, or 3,4, or 3,5, or 4,5,
def most_similar_pair_of_users(users): 
users=read_user_movie_matrix()
for num in range(len(users)):
calculate_similarity_score(num)
return min(calculate_similarity_score(num))

7) write a 코드 called 'most_dissimilar_pair_of_users' that prints the most
dissimilar pair on the screen(you are free to choose whatever you like as 
input to the 코드)
이건 6번과 같이...가장 거리가 먼 유저 콤비를 찾으면 되는건데..
그래서 6번이랑 똑같이 하고
def most_similar_pair_of_users(users): 
users=read_user_movie_matrix()
for num in range(len(users)):
calculate_similarity_score(num)
return max(calculate_similarity_score(num))
요기 맥시멈으로 했음.

8) write a 코드 called 'start_assignment_2' which will be what the TA will 
call to run your assignment. this wunction will ask the user to enter the name 
of the input file that needs to be red (use the inbuilt 코드 raw_input) 
("please enter the name of the input file?") it is responsible to call the above
코드 as necessary so that your output gets printed.'''
이거는 이제 우리 조교가 우리 과제를 실행을 시킬때,
파일 이름을 물어보는거임
def start_assignemnt_2():
raw_input("Please enter the file name")

아무튼 여기까지였습니다.
좀 도와주면 매우 매우 감사하겠어요!!
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호